JVM의 계약 ABI 및 재귀 길이 접두사.
ABI 사양 : https://solidity.readthedocs.io/en/latest/abi-spec.html
RLP 사양 : https://ethereum.org/en/developers/docs/data-tructures-and-encoding/rlp
SHA-256 (Headlong-12.3.3.jar) : 9B577AF538D30FFC05133425C8B0BFF3A79BCBA99955B322D2D2D2D2D2D2D25B27150CC
함수 baz = function.parse ( "baz (uint32, bool)"); // 서명을 정식화하고 구문 분석합니다. // orfunction f2 = function.fromjson ( "{"type ":"function ","name ":"foo ","inputs ": [{"name ":"complex_nums ","type ":"tuple [] ","com 조랑말 ": [{"name ":"real ","type ":"고정 168x10 "}, {"name ":"Imaginary ","type ":"고정 168x10 "}}}}"); pair <long, 부울> bazargs = tuple.of (69l, true); tuple complexnums = single.of (new tuple [] {tuple.of (new bigdecimal ( "0.0090000000"), New BigDecimal ( "1.95000000")); // 두 가지 동등한 스타일 : Bytebuffer Bazcall = baz.encodecall (bazargs); Bytebuffer bazcall2 = baz.encodecallwithargs (69l, true); System.out.println ( "baz call hex : n" + strings.encode (bazcall) + "n"); // 16 진수 인코딩 (0x 접두사 없음) 튜플 recovereDargs = baz.decodecall (bazcall2); // 인코딩을 원래 argssystem.out.println으로 다시 디코딩합니다 ( "baz args : n" + recoveredargs + "n"); // toString () system.out.println ( "Equal : n" + recoyedArgs.equals (bazargs) + "n"); // 평등을 테스트합니다. // human-readable, 디버깅 함수 호출 (4 바이트 선택기로 시작하는 입력) System.out.out.println ( "Baz args debug : n" + baz.getInputs (). Annotate (bazargs) + "n") ; // SELECTORSYSTEM.out.println없이 인코딩을 디버깅 할 수있는 사람-읽기 가능 + f2.getInputs (). Annotate (ComplexNums));
함수 foo = function.parse ( "foo ((고정 [], int8) [1] [] [5])", "(int, string)"); // 디코드 리턴 유형 (int256, String) 튜플 디코딩 = foo.decodereturn (fasthex.decode ( "000000000000000000000000000000000000000000000000000000000000002a"+ "0000000000000000000000000000000000000000000000000000000000000000000040"+ "000000000000000000000000000000000000000000000000000000000000000000000000000e"+ "59616F62616E674569676874793900000000000000000000000000000000") ") ); system.out.println (decoded.equals (tuple.of (biginteger.valueof (42L), "yaobangeighty9")));
function footwo = function.parse ( "footwo ()", "(uint8)"); int returned = footwo.decodesingletonreturn (fasthex.decode ( "000000000000000000000000000000ff")); // uint8은 intsystem.out.println (returned)에 해당합니다.
TupleType <Tuple> tt = tupleType.parse ( "(bool, address, int72 [] []); bytebuffer b0 = tt.encode (tuple.of (false, address.wrap ("0x5290840009852786e0f7030069857d2e4169e7 ")))), New biginteger [0] [])); // tuple t = tt.decode (b0); // 튜플을 디코딩합니다 (바이트 버퍼의 위치를 전진시키는 부작용) // 또는 ... 주소 a = tt.decode (b0, 1); // decode onde index 1system.out.println (a); tuple t2 = tt.decode (b0, 0, 2); // indices 0 및 2system.out.println (t2); 바이트 버퍼 b1 = tt. <abitype <biginteger [] [] >> get (2) .encode (new biginteger [] [] {}); // int72 만 인코딩 [] []
이벤트 <?> event = event.fromjson ( "{"type ":"event ","name ":"an_event ","입력 ": [{"name ":"a ","type ":"bytes ", "색인": true}, { "name": "b", "type": "uint256", "indexed": false}], "익명": true} "); tuple args = event.decodeargs (new Byte [] [] {new Byte [32]}, new Byte [32]); System.out.println (event); System.out.println (Args); // 유형을 만듭니다. 직접 (고급) ArrayType <AbityPe <대상>,?, Object> at = typeCatory.create ( "(주소, int) []"); ArrayTepe <tupletype <tuple>, tuple, tuple []> at2 = typefactory.create ( "(주소, int) []"); arraytype <tupletype <pair <주소, biginteger >>, 쌍 <주소, biginteger>, 쌍 <주소, biginteger> []> at3 = typeCatory.create ( "(주소, int) []"); abitype <object> unknown = typefactory.create (at.getCanonicalType ());
// 예제의 경우 클래스 학생을 구현하는 학생 (byte [] rlp) {iterator <rlpitem> iter = rlpdecoder.rlp_strict.sequenceiterator (rlp); this.name = iter.next (). asstring (strings.utf_8); this.gpa = iter.next (). asfloat (false); this.publickey = iter.next (). asbytes (); this.balance = new bigdecimal (iter.next (). asbigint (), iter.next (). asint ()); } @OverRidePublic Object [] toobjectArray () {return new Object [] {// byte [] strings.decode (이름, strings.utf_8), floatingpoint.tobytes (gpa), publickey, balance.unscaledvalue (). (), integers.tobytes (balance.scale ()) // 객체 포함 [] 또는 반복 가능하며 그 요소는 RLP 목록 (다른 목록을 포함 할 수 있음)으로 인코딩됩니다.}; } @overridepublic byte [] torlp () {return rlpencoder.sequence (toobjectarray ()); }
이제 Maven Central Repository에서 사용할 수 있습니다.
또는 로컬 빌드 :
gradle publishToMavenLocal
또는 mvn install
사용하여 프로젝트를 복제하고 로컬 Maven 저장소에 설치 한 다음 종속성으로 선언하십시오.
구현 ( "com.esaulpaugh : Headlong : 12.3.4-SnapShot"))))
<의존성> <groupid> com.esaulpaugh </groupid> <artifactid> Headlong </artifactid> <버전> 12.3.4-snapshot </version> </의존성>
대안으로 :
build/libs
에 출력하는 gradle build
또는 gradle jar
실행
target
출력을하는 mvn package
사용하십시오
build/lib
에 출력하는 ant all build-jar
실행하십시오
프로젝트 의존성으로 머리를 추가하십시오
x86-64의 Graalvm 20.0.2
https://github.com/esaulpugh/headlong-cli
https://github.com/esaulpugh/headlong-endroid
최적화 된 구현도 포함합니다.
EIP-778 이더 리움 노드 레코드
EIP-55 혼합 사례 체크섬 주소 인코딩
Keccak
16 진
Headlong은 ABI 패키지의 GSON v2.10.1에 따라 다릅니다. 테스트 스위트는 실행하는 데 1 분도 채 걸리지 않아야합니다. 테스트 패키지에는 주니트가 필요합니다. 항아리 크기는 ~ 128 kib입니다. Java 8+.
포장 된 인코딩 (및 디코딩) 및 RLP 객체 표기법과 같은 더 많은 정보는 위키를 참조하십시오 : https://github.com/esaulpugh/headlong/wiki
Apache 2.0 용어에 따라 라이센스가 부여됩니다