Contrato ABI e prefixo de comprimento recursivo facilitados para a JVM.
ABI Spec: https://solity.readthedocs.io/en/latest/abi-spec.html
RLP Spec: https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp
SHA-256 (Headlong-12.3.3.Jar): 9B577AF538D30FFC05133425C8B0BFF3A79BCBA99955B3222DD2D825B27150CC
Função baz = function.parse ("baz (uint32, bool)"); // canonicaliza e analisa qualquer assinatura // Orfunction f2 = Function.fromjson ("{" type ":" function "," nome ":" foo "," entradas ": [{" name ":" complex_nums "," type ":" tuple [] "," com PONENTS ": [{" Nome ":" Real "," Type ":" FIRL168X10 "}, {" Nome ":" imaginário "," Type ":" FIRL168X10 "}]}]}"); par <Long, Booleano> bazargs = tupla.of (69l, true); tuple complexNums = single.of (nova tupla [] {tuple.of (new bigdecimal ("0,0090000000"), novo bigdecimal ("1.9500000000)); Dois estilos equivalentes: bytebuffer bazcall = Baz.Encodecall (Bazargs); ByteBuffer BazCall2 = Baz.Encodecallwithargs (69L, True); System.out.println ("Baz chama Hex: N" + Strings.Encode (BazCall) + "N"); // codificação hexadecimal (sem prefixo 0x) tuple recuperedargs = baz.decodecall (BazCall2); // decodifica a codificação de volta ao argssystem.out.println original ("baz args: n" + recuperedargs + "n"); // tostring () system.out.println ("igual: n" + recuperedargs.equals (bazargs) + "n"); // teste para EqualitySystem.out.println ("Baz Call Debug: n" + Baz.annotatecall (Bazcall.array ()) + "n"); // Human-Lablelable, para chamadas de função de depuração (espera que a entrada seja iniciada com seletor de 4 bytes) System.out.println ("Baz args Debug: n" + baz.getInputs (). Annotate (bazargs) + "n") ; // Human-lablelable, para codificações de depuração sem um seletorsystem.out.println ("F2 chamadas depuração: n" + f2.annotatecall (complexNums) + "n"); system.out.println ("f2 args depure: n" + f2.getInputs (). Annotate (complexNums)); Function foo = function.parse ("foo ((corrigido [], int8) [1] [] [5])", "(int, string)"); // decodificar o tipo de retorno (int256, string) tupla decodificada = Foo.DecodeReTurn (Fasthex.Decode ("000000000000000000000000000000000000000000000000000000000000000000000000002A"+ "000000000000000000000000000000000000000000000000000000000000000000000000000040 "59616F62616E6745696768747939000000000000000000000000000000000000000000")
); System.out.println (decodificado.equals (tuple.of (biginteger.valueof (42L), "yaobangeighty9"))); Function footwo = function.parse ("footwo ()", "(uint8)"); int return = footwo.decodesingLetoNeRurn (fasthex.decode ("00000000000000000000000000000000000000000000000000000000000000000000000000FFFFFFFF // uint8 corresponde a intsystem.out.println (retornado); TupleType <tuple> tt = tupleType.parse ("(bool, endereço, int72 [] [])"); bytebuffer b0 = tt.encode (tuple.of (false, endereço.wrap ("0x5290840009852786e0f703006987d24d21e "03006987d297d2e. Biginteger [0] [])); // tupla t = tt.Decode (b0); // decodificar a tupla (tem o efeito colateral de avançar a posição do bytebuffer) // ou ... endereço a = tt.decode (b0, 1); // decodificar apenas índice 1System.out.println (a); tupla t2 = tt.decode (b0, 0, 2); // decodificar apenas índices 0 e 2system.out.println (t2); bytebuffer b1 = tt. // codifica apenas int72 [] [] Evento <?> Event = event.fromjson ("{" type ":" event "," name ":" an_event "," entradas ": [{" name ":" a "," type ":" bytes ", "Indexado": true}, {"nome": "b", "tipo": "uint256", "indexado": false}], "anonymous": true} "); tupla args = event.Decodeargs (novo byte [] [] {new Byte [32]}, novo byte [32]); System.out.println (event); System.out.println (args); // Crie qualquer tipo diretamente (avançado) ArrayType <abitype <ject> ,?, objeto> at = Typefactory.create ("(endereço, int) []"); ArrayType <PpleType <tuple>, tupla, tupla []> at2 = typefactory.create ("(endereço, int) []"); ArrayType <TupLetype < <Endereço, biginteger >>, par <endereço, biginteger>, par <endereço, biginteger> []> at3 = Typefactory.create ("(endereço, int) []"); abitype <ject> desconhecido = timefactory.create (at.getCanonicalType ()); // Para um exemplo, aluno da classe implementando algum exemplo interfacePublic Student (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 = novo bigdecimal (iter.next (). Asbigint (), iter.next (). Asint ());
} @OverridePublic Object [] toObjectArray () {retorna novo objeto [] {// Instâncias de byte [] strings.decode (nome, strings.utf_8), flutuatingpoint.tobytes (gPA), publicKey, balance.unscaledValue (). (), Integers.tobytes (balance.scale ()) // incluem um objeto [] ou Iterable e seus elementos serão codificados como uma lista RLP (que pode incluir outras listas)};
} @OverridePublic byte [] torlp () {return rlpencoder.sequence (toObjectArray ());
}Agora disponível no repositório central do MAVEN.
Ou construir localmente:
Clone o projeto e instale no seu repositório Maven local usando gradle publishToMavenLocal ou mvn install , depois o declare como uma dependência:
Implementação ("com.esaulpaugh: headlong: 12.3.4-Snapshot") <pendência>
<GrupidId> com.esaulpaugh </frugiD>
<TarfactId> Headlong </stifactId>
<Versão> 12.3.4-SNAPSHOT </SERSUSTE>
</dependency>Alternativamente:
Execute gradle build ou gradle jar cuja saída para build/libs
Use mvn package quais saídas para target
Execute ant all build-jar que produz a build/lib
Adicione de cabeça como uma dependência do projeto
Graalvm 20.0.2 em x86-64
https://github.com/esaulpaugh/headlong-cli
https://github.com/esaulpaugh/headlong-android
Também inclui implementações otimizadas de:
Registros do nó EIP-778 Ethereum
EIP-55 Endereço de soma de verificação mista codificação
KECCAK
hexadecimal
Depende de depende do GSON v2.10.1 para o pacote ABI. O conjunto de testes deve levar menos de um minuto para ser executado. Os pacotes de teste requerem Junit. O tamanho da jarra é ~ 128 kib. Java 8+.
Veja o wiki para mais, como a codificação embalada (e decodificação) e a notação do objeto RLP: https://github.com/esaulpaugh/headlong/wiki
Licenciado sob os termos do Apache 2.0