عقد ABI و premix طول العودية جعلت سهلة ل JVM.
ABI Spec: https://solidity.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.jar): 9B577F538D30FFC05133425C8B0BFF3A79BCBA999955B3222DD2D825B27150CC
وظيفة baz = function.parse ("baz (uint32 ، bool)") ؛ // canonicalies وتوصيف أي توقيع // orfunction f2 = function.fromjson ("{" type ":" function "،" name ": ponents ": [{" name ":" real "،" type ":" flex168x10 "} ، {" name ":" Exicalinar Boolean> bazargs = tuple.of (69L ، true) ؛ tuple complexnums = single.of (new tuple [] {tuple.of (new bigdecimal ("0.0090000000") ، new bigdecimal ("1.95000000")}) ؛ //) ؛ اثنين من الأسلوب المكافئ: bazcall bytebuffer = baz.encodecall (bazargs) ؛ bytebuffer bazcall2 = baz.encodecallwithargs (69l ، true) ؛ system.out.println ("baz call hex: n" + setrings.encode (bazcall) + "n") ؛ // الترميز السداسي (بدون بادئة 0x) tuple RecoverArgs = baz.decodecall (bazcall2) ؛ // فك التشفير مرة أخرى إلى argssystem.out.println الأصلي ("baz args: n" + RecoverAdargs + "n") ؛ // toString () system.out.println ("equal: n" + RecoverAdargs.equals (bazargs) + "n") ؛ // test for qualitysystem.out.println ("baz call debug: n" + baz.annotateCall (bazcall.array ()) + "n") ؛ // قابلة للقراءة البشرية ، لمكالمات دالة تصحيح الأخطاء (تتوقع أن تبدأ المدخلات بـ 4-بايت) System.out.println ("BAZ args debug: n" + baz.getInputs (). include (bazargs) + "n") ؛ // قابلة للقراءة البشرية ، لترميز تصحيح الأخطاء بدون مختار. + f2.getInputs ().
function foo = function.parse ("foo ((ثابت [] ، int8) [1] [] [5])" ، "(int ، string)") ؛ // decode type (int256 ، string) decoded = Foo.Decodereturn (Fasthex.Decode ("00000000000000000000000000000000000000000000000000000000000000002a"+ "000000000000000000000000000000000000000000000000000000000040"+ "00000000000000000000000000000000000000000000000000000000e "59616F62616E67456967687479390000000000000000000000000000000000") ) ؛ system.out.println (decoded.equals (tuple.of (biginteger.valueof (42l) ، "yaobangeighty9")))) ؛
Function Footwo = function.parse ("footwo ()" ، "(uint8)") ؛ int return = footwo.decodesingletonreturn (fasthex.decode ("00000000000000000000000000000000000000000000000000000000 // uint8 يتوافق مع intsystem.out.println (return) ؛
tupletype <tuple> tt = tupletype.parse ("(bool ، address ، int72 [] []) BigInteger [0] [])) ؛ // tuple t = tt.decode (b0) ؛ // فك تشفير tuple (له تأثير جانبي للتقدم في موضع bytebuffer) // أو ... العنوان A = tt.decode (B0 ، 1) ؛ // decode index ondix 1system.out.println (a) ؛ tuple t2 = tt.decode (b0 ، 0 ، 2) ؛ // decode فقط مؤشرات 0 و 2System.out.println (t2) ؛ bytebuffer b1 = tt. <abitype <biginteger [] >> get (2) .encode (new BigInteger []] {}) ؛ // encode int72 [] [] فقط []
الحدث <؟> event = event.fromjson ("{" type ":" event "،" name ":" an_event "، "فهرسة": TRUE} ، {"name": "b" ، "type": "uint256" ، "adesced": false}] ، "Anonymous: True}") ؛ Tuple args = event.decodeArgs (byte new [] [] {new byte [32]} ، byte new [32]) ؛ system.out.println (event) ؛ system.out.println (args) ؛ // إنشاء أي نوع مباشرة (متقدم) arraytype <abitype <bomf> ،؟ ، الكائن> في = kypefactory.create ("((العنوان ، int) []") ؛ arraytype <tupletype <tuple> ، tuple ، tuple []> at2 = ortorfactory.create ("(العنوان ، int) []") <العنوان ، biginteger >> ، زوج <العنوان ، biginteger> ، الزوج <العنوان ، biginteger> []> at3 = kypactory.create ("(العنوان ، int) []") ؛ abitype <object> unknown = aryfactory.create (at.getCanonicalType ()) ؛
// للحصول على مثال ، يقوم طالب بالفئة بتنفيذ بعض مثال interfacepublic student (byte [] rlp) {iterator <RlPitem> iter = rlpdecoder.rlp_strict.equenceiterator (RLP) ؛ this.name = iter.next (). asstring (untrings.utf_8) ؛ this.gpa = iter.next (). asfloat (false) ؛ this.publickey = iter.next (). new BigDecimal (iter.next (). asbigint () ، iter.next (). asint ()) ؛ } Overridepublic Object [] ToobjectArray () {return compour new [] {// ظروف byte [] strings.decode (name ، setrings.utf_8) ، floatingpoint.tobytes (gpa) ، publickey ، balance.unscaledvalue (). tobytearray () ، imentegers.tobytes (balance.scale ()) // تضمين كائن [] أو سيتم ترميز العناصر الخاصة بها وعناصرها كقائمة RLP (والتي قد تتضمن قوائم أخرى)} ؛ } overridepublic byte [] torlp () {return rlpencoder.sequence (toobjectarray ()) ؛ }
متوفر الآن في مستودع مافن المركزي.
أو بناء محليًا:
استنساخ المشروع والتثبيت على مستودع Maven المحلي باستخدام gradle publishToMavenLocal
أو mvn install
، ثم أعلن أنه تبعية:
التنفيذ ("com.esaulpaugh: headlong: 12.3.4-snapshot")
<premency> <rouckid> com.esaulpaugh </roughid> <StifactId> headlong </stifactid> <splection> 12.3.4-snapshot </version> </التبعية>
بدلاً عن ذلك:
قم بتشغيل 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
يتضمن أيضًا تطبيقات محسّنة لـ:
EIP-778 سجلات عقدة Ethereum
EIP-55 تخليص عنوان الفحوصات المختلطة
كيكاك
سداسي عشري
يعتمد Headlong على GSON V2.10.1 لحزمة ABI. يجب أن يستغرق جناح الاختبار أقل من دقيقة واحدة للركض. تتطلب حزم الاختبار Junit. حجم الجرة ~ 128 KIB. جافا 8+.
انظر Wiki للمزيد ، مثل الترميز المعبأ (وفك التشفير) و RLP كائن تدوين: https://github.com/esaulpaugh/headlong/wiki
مرخصة بموجب شروط Apache 2.0