契約ABIと再帰長のプレフィックスは、JVMにとって簡単になりました。
ABI仕様: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):9B577AF538D30FFC05133425C8B0BFF3A79BCBA999955B32222DD2D825B27150CC
function baz = function.parse( "baz(uint32、bool)"); // CanOnicalize and ParseS任意の署名// orfunction f2 = function.fromjson( "{" type ":" function "、" name ":" foo "、" inputs ":[{" name ":" complex_nums "、" type ":" tuple [] "、" com Ponents ":[{" name ":" real "、" type ":" sixed168x10 "}、{" name ":" imaginary "、" type ":" sixed168x10 "}]}}";ペア<long、 boolean> bazargs = tuple.of(69l、true); tuple complexnums = single.of(new Tuple [] {tuple.of(new bigdecimal( "0.0090000000")、new bigdecimal( "1.9500000000")}); ///////////// 2つの同等のスタイル: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 Recoveredargs = Baz.Decodecall(BazCall2); //エンコードを元のargssystem.out.println( "baz args:n" + recoveredargs + "n"); // toString()system.out.println( "equal:n" + recoveredargs.equals(bazargs) + "n"); // equalitysystem.out.printlnのテスト( "baz call debug:n" + baz.annotatecall(bazcall.array()) + "n"); // human-readable、for debugging function call(4 byte selectorで入力が開始されることを予想します)out.println( "baz args debug:n" + baz.getinputs()。annotate(bazargs) + "n") ; // selectorSystem.out.out.println( "f2 call debug:n" + f2.annotatecall(complexnums) + "n"); system.out.println( "f2 args debug:n n"); + f2.getinputs()。annotate(complexnums));
function foo = function.parse( "foo((sixed []、int8)[1] [] [5])"、 "(int、string)"); //デコードリターンタイプ(int256、string)tuple decoded = foo.decodeReturn(FastHex.decode( "000000000000000000000000000000000000000000000000000000000000002A"+ "0000000000000000000000000000000000000000000000000000000000000040"+ "000000000000000000000000000000000000000000000000000000000000000e"+ "59616F62616E67456967687479399000000000000000000000000000000") ); system.out.println(decoded.equals(tuple.of(biginteger.valueof(42l)、 "yaobangeighighty9")));
関数footwo = function.parse( "footwo()"、 "(uint8)"); int returned = footwo.decodesingletonreturn(fasthex.decode( "000000000000000000000000000000000000000000000000000000000000000000000000FF")); // uint8はintsystem.out.println(returned)に対応します。
tupletype <tuple> tt = tupletype.parse( "(bool、address、int72 [] [])"); bytebuffer b0 = tt.encode(false、address.wrap( "0x52908400098527886E0F70300698888D2E4169")マネーbiginteger [0] []); // tuple t = tt.decode(b0); //タプルをデコードします(bytebufferの位置を進める副作用があります)//または...アドレスa = tt.decode(b0、1); // decodeのみインデックス1system.out.println(a); tuple t2 = tt.decode(b0、0、2); //インデックスのみをデコード0および2System.out.println(t2); bytebuffer b1 = tt。<abitype <biginteger [] [] >> get(2).encode(new biginteger [] [] {}); // int72 [] []のみをエンコードする
event <? 「indexed」:true}、{"name": "b"、 "type": "uint256"、 "indexed":false}]、 "anonymous":true} "); tuple args = event.decodeargs(new byte [] [] {new byte [32]}、new byte [32]); system.out.println(event); system.out.println(args); //任意のタイプを作成する直接(Advanced)ArrayType <AbityPe <Object>、?、object> at = TypeFactory.create( "(address、int)[]"); arrayType <tupletype <tuple>、tuple、tuple []> at2 = typefactory.create( "(address、int)[]"); arrayType <tupletype <pair <アドレス、biginteger >>、ペア<アドレス、biginteger>、ペア<アドレス、biginteger> []> at3 = TypeFactory.create( "(address、int)[]"); abitype <object> nown = typeFactory.create(at.getCanonicalType());
//例の場合は、いくつかの例Interfacepublic Student(byte [] rlp){iterator <rlpitem> iter = rlpdecoder.rlp_strict.sequenceTerator(rlp); this.name = iter.next()。asstring(strings.utf_8); this.gpa = iter.next()。asfloat(false); this.publickey = iter.next() new bigdecimal(iter.next()。asbigint()、iter.next()。asint()); } @OverridePublic object [] ToobbjectArray(){return new object [] {// byte [] strings.decode(name、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:heandlong: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/esaulpaugh/headlong-cli
https://github.com/esaulpaugh/headlong-android
最適化された実装も含まれます。
EIP-778 Ethereumノードレコード
EIP-55混合ケースチェックサムアドレスエンコーディング
ケッカック
16進
ヘッドロングは、ABIパッケージのGSON v2.10.1に依存します。テストスイートは実行に1分もかかりません。テストパッケージにはJunitが必要です。瓶のサイズは〜128キブです。 Java 8+。
パックされたエンコード(およびデコード)やRLPオブジェクトの表記などの詳細については、wikiをご覧ください:https://github.com/esaulpaugh/headlong/wiki
Apache 2.0の条件に基づいてライセンスされています