Skip to content

Conversation

@pablojorge
Copy link
Contributor

Intro

This PR adds support for newer versions of Polkadot and introduces several improvements and fixes.

Changes

Support for Metadata v12 and refcount size change

In Polkadot v0.8.25 (https://github.com/paritytech/polkadot/releases/tag/v0.8.25), the metadata was updated to v12 (to include a new index field for modules) and the refcount field of AccountInfo was extended from 8 to 32 bits.

Commits:

References:

Related issues:

Fixes

CompactBigIntWriter fix

The following commit fixes the serialization of CompactBigInts when the MSB is > 127, and the resulting byte array starts with an extra 0x00 (to signal it's a positive value):

Related issues:

Mortal era encoding fix

The following commit fixes the serialization of Mortal eras on both the signature payload and the transaction info of the extrinsic:

Additionally, it extends the ExtrinsicContext.Builder class to allow setting the era and eraBlockHash fields.

Improvements

The PR also extends the PolkadotHttpApi constructor and builder to accept a timeout parameter, and extends the RpcException class to include the data field from JSON error responses.

Commits:

The serialization of BigIntegers may include an extra zero byte as
prefix when the first byte is > 127, to act as a sign bit and distinguish
it from a negative value. We only deal with unsigned values, so we must
ignore that initial zero byte.

Ref: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#toByteArray%28%29

This should fix #32
Additionally, add missing era() and eraBlockHash() methods to the
ExtrinsicContext.Builder class.

Ref: https://github.com/paritytech/substrate/commits/master/primitives/runtime/src/generic/era.rs

(at dbf2163250833e6ac898e7f6c3c8f89f08a7c19d)
Ref: https://github.com/paritytech/polkadot/releases/tag/v0.8.25
Substrate PR: paritytech/substrate#6969

Should fix:
 - #30
 - #39

Metadata obtained from Kusama network at hash:
  0x318f1c8b14fdc9d9624a85b90eb3b2475ac1d19c7dcfcd9fbff25a26ed56f5d0
  (Height 4,909,958)
@CLAassistant
Copy link

CLAassistant commented Nov 18, 2020

CLA assistant check
All committers have signed the CLA.

@codecov-io
Copy link

Codecov Report

Merging #41 (4db9ecb) into master (32df6c0) will increase coverage by 0.27%.
The diff coverage is 94.11%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #41      +/-   ##
============================================
+ Coverage     86.53%   86.80%   +0.27%     
- Complexity      872      887      +15     
============================================
  Files           111      113       +2     
  Lines          2903     2949      +46     
  Branches        423      429       +6     
============================================
+ Hits           2512     2560      +48     
  Misses          278      278              
+ Partials        113      111       -2     
Impacted Files Coverage Δ Complexity Δ
...a/io/emeraldpay/polkaj/scaletypes/AccountInfo.java 100.00% <ø> (ø) 14.00 <0.00> (ø)
...ava/io/emeraldpay/polkaj/api/RpcResponseError.java 58.82% <50.00%> (+1.68%) 5.00 <2.00> (+1.00)
...o/emeraldpay/polkaj/scaletypes/MetadataReader.java 97.97% <66.66%> (-0.03%) 6.00 <0.00> (ø)
.../io/emeraldpay/polkaj/api/AbstractPolkadotApi.java 100.00% <100.00%> (ø) 8.00 <0.00> (ø)
...in/java/io/emeraldpay/polkaj/api/RpcException.java 100.00% <100.00%> (ø) 8.00 <6.00> (+4.00)
.../io/emeraldpay/polkaj/apihttp/PolkadotHttpApi.java 69.87% <100.00%> (+1.52%) 10.00 <0.00> (ø)
...ava/io/emeraldpay/polkaj/apiws/DecodeResponse.java 77.39% <100.00%> (+0.60%) 27.00 <0.00> (+1.00)
...java/io/emeraldpay/polkaj/apiws/PolkadotWsApi.java 74.07% <100.00%> (ø) 17.00 <0.00> (ø)
...meraldpay/polkaj/scaletypes/AccountInfoReader.java 100.00% <100.00%> (ø) 2.00 <0.00> (ø)
.../emeraldpay/polkaj/scaletypes/ExtrinsicReader.java 83.87% <100.00%> (ø) 2.00 <0.00> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32df6c0...4db9ecb. Read the comment docs.

@splix
Copy link
Owner

splix commented Nov 18, 2020

@pablojorge thank you very much for the PR, it fixes few very critical issues. I've checked the commit, everything is good.

The only thing I would comment on is having the Era codec as method in Scale Reader/Writer. I prefer to use the main scale class to provide methods only for basic and common types, and use a generic method (write(ScaleWriter<T> writer, T value)) for other types. I mean that's fine right now, not critical at all, and I'm going to merge your changes as is. Just saying that if you are planing to implement other codecs.

@splix splix merged commit 827f6f3 into splix:master Nov 18, 2020
@pablojorge
Copy link
Contributor Author

Sure! We're glad to contribute!

Regarding the Era codec, yes, maybe adding the methods wasn't really necessary, will have in mind that if we add more

@EmilyCaoHong
Copy link

can you give all of the projects jar or the download url

@nschwermann
Copy link
Contributor

nschwermann commented Aug 23, 2021

Hey guys, where is the metadata found (text file for test)? I can get support for new metadata version (13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants