คำนำหน้าสัญญา ABI และความยาวแบบเรียกซ้ำได้ง่ายสำหรับ JVM
ABI Spec: https://solidity.readthedocs.io/en/latest/abi-spec.html
ข้อมูลจำเพาะ RLP: https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp
SHA-256 (headlong-12.3.3.jar): 9B577AF538D30FFC05133425C8B0BFF3A79BCBA99955B3222DD2D825B27150CC
function baz = function.parse ("baz (uint32, bool)"); // Canonicalizes และวิเคราะห์ลายเซ็นใด ๆ // orfunction f2 = function.fromjson ("{" type ":" function "," name ":" foo "," inputs ": [{" name ":" complex_nums "," type ":" tuple [] "," com ponents ": [{" name ":" real "," type ":" fixed168x10 "}, {" name ":" Imaginary "," type ":" recide168x10 "}]}]}"); บูลีน> bazargs = tuple.of (69l, true); tuple complexnums = single.of (tuple ใหม่ [] {tuple.of (ใหม่ bigdecimal ("0.0090000000"), ใหม่ BigDecimal (1.9500000000 ")) สองสไตล์ที่เทียบเท่า: Bytebuffer Bazcall = baz.encodecall (bazargs); bytebuffer bazcall2 = baz.encodecallwithargs (69L, true); system.out.println ("baz call hex: n" + strings.encode (bazcall) + "n"); // การเข้ารหัส hexadecimal (ไม่มีคำนำหน้า 0x) tuple dearchedargs = baz.decodecall (bazcall2); // ถอดรหัสการเข้ารหัสกลับไปที่ argssystem.out.out.println ("baz args: n" + recoveedargs + "n"); // TOSTRING () System.out.println ("equal: n" + dearchedargs.equals (bazargs) + "n"); // ทดสอบสำหรับ EqualitySystem.out.println ("Baz Call Debug: N" + Baz.Annotatecall (bazcall.array ()) + "n"); // มนุษย์ที่อ่านได้สำหรับการเรียกร้องการเรียกร้องการเรียกใช้ (คาดว่าอินพุตจะเริ่มต้นด้วยตัวเลือก 4-byte) system.out.println ("baz args debug: n" + baz.getinputs (). คำอธิบายประกอบ (bazargs) + "n") ; // มนุษย์อ่านได้สำหรับการดีบักการเข้ารหัสโดยไม่มี selectorsystem.out.println ("F2 Call Debug: N" + F2.AnnotateCall (ComplexNums) + "N"); System.out.println ("F2 Args Debug: N" + f2.getInputs (). คำอธิบายประกอบ (ComplexNums));
function foo = function.parse ("foo ((แก้ไข [], int8) [1] [] [5])", "(int, string)"); // decode type return type (int256, string) tuple decoded = foo.decodereturn (fasthex.decode ("0000000000000000000000000000000000000000000000000000000000000000002A" "0000000000000000000000000000000000000000000000000000000000000040"+ "000000000000000000000000000000000000000000000000000000000000000e"+ "59616F62616E674569676874793900000000000000000000000000000000000000") ); system.out.println (decoded.equals (tuple.of (biginteger.valueof (42l), "yaobangeight9"))));
Function fooTwo = Function.parse("fooTwo()", "(uint8)");int returned = fooTwo.decodeSingletonReturn(FastHex.decode("00000000000000000000000000000000000000000000000000000000000000FF")); // uint8 สอดคล้องกับ intsystem.out.println (ส่งคืน);
TupleType <Tuple> tt = tupleType.parse ("(บูล, ที่อยู่, int72 [] [])"); bytebuffer b0 = tt.encode (tuple.of (เท็จ, address.wrap ("0x5290840009852786 biginteger [0] [])); // tuple t = tt.decode (b0); // ถอดรหัส tuple (มีผลข้างเคียงของการพัฒนาตำแหน่งของ Bytebuffer) // หรือ ... ที่อยู่ a = tt.decode (b0, 1); // ถอดรหัสเฉพาะดัชนี 1system.out.println (a); tuple t2 = tt.decode (b0, 0, 2); // ถอดรหัสเฉพาะดัชนี 0 และ 2System.out.println (t2); bytebuffer b1 = tt. <abitype <biginteger [] [] >> รับ (2) .encode (ใหม่ biginteger [] [] {}); // เข้ารหัสเฉพาะ int72 [] []
เหตุการณ์ <?> event = event.fromjson ("{" type ":" event "," name ":" an_event "," inputs ": [{" name ":" a "," type ":" bytes ", "ดัชนี": จริง}, {"ชื่อ": "b", "type": "uint256", "ดัชนี": false}], "anonymous": true} "); tuple args = event.decodeargs (byte ใหม่ [] [] {byte ใหม่ [32]}, byte ใหม่ [32]); system.out.println (event); system.out.println (args); // สร้างประเภทใดก็ได้ โดยตรง (ขั้นสูง) ArrayType <AbityPe <Ojuct>,?, Object> at = typeFactory.create ("(ที่อยู่, int) []"); arrayType <tupleType <Tuple>, tuple, tuple []> at2 = typeFactory.create ("(ที่อยู่, int) []"); <ที่อยู่, biginteger >>, pair <address, biginteger>, pair <address, biginteger> []> at3 = typeFactory.create ("(ที่อยู่, int) []"); abitype <jobch> unknown = typeFactory.create (at.getCanonicalType ());
// สำหรับตัวอย่างชั้นเรียนนักเรียนใช้ตัวอย่างบางส่วนของ InterfacePublic Student (BYTE [] RLP) {Iterator <RlPitem> iter = RLPDecoder.rlp_strict.equenceIterator (RLP); this.name = iter.next (). asstring (strings.utf_8); this.gpa = iter.next (). asfloat (เท็จ); this.publickey = iter.next (). asbytes (); this.balance = ใหม่ bigdecimal (iter.next (). asbigint (), iter.next (). asint ()); } @overridepublic Object [] toobjectArray () {ส่งคืนวัตถุใหม่ [] {// อินสแตนซ์ของไบต์ [] strings.decode (ชื่อ, strings.utf_8), floatingpoint.tobytes (gpa), publickey, balance.unscaledValue () (), integers.tobytes (balance.scale ()) // รวมวัตถุ [] หรือ iterable และองค์ประกอบของมันจะถูกเข้ารหัสเป็นรายการ RLP (ซึ่งอาจรวมถึงรายการอื่น ๆ )}; } @OverridePublic byte [] torlp () {return rlpencoder.equence (toobjectarray ()); -
ตอนนี้มีอยู่ในที่เก็บ Maven Central
หรือสร้างในพื้นที่:
โคลนโครงการและติดตั้งไปยังที่เก็บ Maven ในพื้นที่ของคุณโดยใช้ gradle publishToMavenLocal
หรือ mvn install
จากนั้นประกาศว่าเป็นการพึ่งพา:
การใช้งาน ("com.esaulpaugh: headlong: 12.3.4-snapshot")
<การพึ่งพา> <RoupID> com.esaulpaugh </roupId> <ArtIfactId> headlong </artifactid> <Sersion> 12.3.4-SNAPSHOT </Sersion> </dermentency>
หรือ
เรียกใช้ gradle build
หรือ gradle jar
ซึ่งส่งออกเพื่อ build/libs
ใช้ mvn package
ซึ่งส่งออกไปยัง target
ดำเนินการ ant all build-jar
ซึ่งส่งออกเพื่อ build/lib
เพิ่มหัวก้นเป็นโครงการพึ่งพา
graalvm 20.0.2 บน x86-64
https://github.com/esaulpaugh/headlong-cli
https://github.com/esaulpaugh/headlong-android
รวมถึงการใช้งานที่ดีที่สุดของ:
บันทึกโหนด ETHEREUM ETHEREUM ETHEREUM
การเข้ารหัสการเข้ารหัสที่อยู่ตรวจสอบกรณี EIP-55
เค็กคัก
เลขฐานสิบหก
Headlong ขึ้นอยู่กับ GSON v2.10.1 สำหรับแพ็คเกจ ABI ชุดทดสอบควรใช้เวลาน้อยกว่าหนึ่งนาทีในการวิ่ง แพ็คเกจทดสอบต้องใช้ Junit ขนาดขวดคือ ~ 128 kib Java 8+
ดูวิกิสำหรับข้อมูลเพิ่มเติมเช่นการเข้ารหัสที่บรรจุ (และการถอดรหัส) และสัญกรณ์วัตถุ RLP: https://github.com/esaulpaugh/headlong/wiki
ได้รับใบอนุญาตภายใต้ข้อกำหนด Apache 2.0