Skip to content

Commit 53c1093

Browse files
authored
Increase precision of UCompact type to scale max (#85)
* Revert "Add ExtrinsicSignatureV5 (#68)" This reverts commit 461cf42. * Increase precision ucompact to max * remove test codee * Move to scale and make Reverse function public * Clean event record SomeOffline test * imports * review comments
1 parent e238735 commit 53c1093

19 files changed

Lines changed: 226 additions & 103 deletions

main_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func Example_makeASimpleTransfer() {
203203
panic(err)
204204
}
205205

206-
c, err := types.NewCall(meta, "Balances.transfer", bob, types.UCompact(12345))
206+
c, err := types.NewCall(meta, "Balances.transfer", bob, types.NewUCompactFromUInt(12345))
207207
if err != nil {
208208
panic(err)
209209
}
@@ -238,9 +238,9 @@ func Example_makeASimpleTransfer() {
238238
BlockHash: genesisHash,
239239
Era: types.ExtrinsicEra{IsMortalEra: false},
240240
GenesisHash: genesisHash,
241-
Nonce: types.UCompact(nonce),
241+
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
242242
SpecVersion: rv.SpecVersion,
243-
Tip: 0,
243+
Tip: types.NewUCompactFromUInt(0),
244244
}
245245

246246
// Sign the transaction using Alice's default account
@@ -413,7 +413,7 @@ func Example_transactionWithEvents() {
413413
panic(err)
414414
}
415415

416-
amount := types.UCompact(12345)
416+
amount := types.NewUCompactFromUInt(12345)
417417

418418
c, err := types.NewCall(meta, "Balances.transfer", bob, amount)
419419
if err != nil {
@@ -454,9 +454,9 @@ func Example_transactionWithEvents() {
454454
BlockHash: genesisHash,
455455
Era: types.ExtrinsicEra{IsMortalEra: false},
456456
GenesisHash: genesisHash,
457-
Nonce: types.UCompact(nonce),
457+
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
458458
SpecVersion: rv.SpecVersion,
459-
Tip: 0,
459+
Tip: types.NewUCompactFromUInt(0),
460460
}
461461

462462
fmt.Printf("Sending %v from %#x to %#x with nonce %v", amount, signature.TestKeyringPairAlice.PublicKey, bob.AsAccountID, nonce)

rpc/author/pending_extrinsics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ import (
2626
func TestAuthor_PendingExtrinsics(t *testing.T) {
2727
res, err := author.PendingExtrinsics()
2828
assert.NoError(t, err)
29-
assert.Equal(t, []types.Extrinsic{types.Extrinsic{Version: 0x84, Signature: types.ExtrinsicSignatureV4{Signer: types.Address{IsAccountID: true, AsAccountID: types.AccountID{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, IsAccountIndex: false, AsAccountIndex: 0x0}, Signature: types.MultiSignature{IsEd25519: true, AsEd25519: types.Signature{0xa0, 0x23, 0xbb, 0xe8, 0x83, 0x40, 0x5b, 0x5f, 0xac, 0x2a, 0xa1, 0x14, 0x9, 0x3f, 0xcf, 0x3d, 0x8, 0x2, 0xd2, 0xf3, 0xd3, 0x71, 0x5e, 0x9, 0x12, 0x9b, 0x0, 0xa4, 0xbf, 0x74, 0x10, 0x48, 0xca, 0xf5, 0x3d, 0x8c, 0x7d, 0x97, 0xe8, 0x72, 0xca, 0xa7, 0x3, 0xe7, 0xd0, 0x4f, 0x17, 0x4a, 0x4e, 0x2e, 0xd4, 0xac, 0xad, 0xee, 0x41, 0x73, 0xa8, 0xb6, 0xba, 0xb7, 0xe4, 0x5c, 0xa, 0x6}, IsSr25519: false, AsSr25519: types.Signature{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, IsEcdsa: false, AsEcdsa: types.Bytes(nil)}, Era: types.ExtrinsicEra{IsImmortalEra: true, IsMortalEra: false, AsMortalEra: types.MortalEra{First: 0x0, Second: 0x0}}, Nonce: 0x3, Tip: 0x0}, Method: types.Call{CallIndex: types.CallIndex{SectionIndex: 0x6, MethodIndex: 0x0}, Args: types.Args{0xff, 0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48, 0xe5, 0x6c}}}}, res) //nolint:lll,dupl
29+
assert.Equal(t, []types.Extrinsic{types.Extrinsic{Version: 0x84, Signature: types.ExtrinsicSignatureV4{Signer: types.Address{IsAccountID: true, AsAccountID: types.AccountID{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, IsAccountIndex: false, AsAccountIndex: 0x0}, Signature: types.MultiSignature{IsEd25519: true, AsEd25519: types.Signature{0xa0, 0x23, 0xbb, 0xe8, 0x83, 0x40, 0x5b, 0x5f, 0xac, 0x2a, 0xa1, 0x14, 0x9, 0x3f, 0xcf, 0x3d, 0x8, 0x2, 0xd2, 0xf3, 0xd3, 0x71, 0x5e, 0x9, 0x12, 0x9b, 0x0, 0xa4, 0xbf, 0x74, 0x10, 0x48, 0xca, 0xf5, 0x3d, 0x8c, 0x7d, 0x97, 0xe8, 0x72, 0xca, 0xa7, 0x3, 0xe7, 0xd0, 0x4f, 0x17, 0x4a, 0x4e, 0x2e, 0xd4, 0xac, 0xad, 0xee, 0x41, 0x73, 0xa8, 0xb6, 0xba, 0xb7, 0xe4, 0x5c, 0xa, 0x6}, IsSr25519: false, AsSr25519: types.Signature{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, IsEcdsa: false, AsEcdsa: types.Bytes(nil)}, Era: types.ExtrinsicEra{IsImmortalEra: true, IsMortalEra: false, AsMortalEra: types.MortalEra{First: 0x0, Second: 0x0}}, Nonce: types.NewUCompactFromUInt(0x3), Tip: types.NewUCompactFromUInt(0x0)}, Method: types.Call{CallIndex: types.CallIndex{SectionIndex: 0x6, MethodIndex: 0x0}, Args: types.Args{0xff, 0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48, 0xe5, 0x6c}}}}, res) //nolint:lll,dupl
3030
}

rpc/author/submit_extrinsic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func TestAuthor_SubmitExtrinsic(t *testing.T) {
27-
ext := types.Extrinsic{Version: 0x84, Signature: types.ExtrinsicSignatureV4{Signer: types.Address{IsAccountID: true, AsAccountID: types.AccountID{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, IsAccountIndex: false, AsAccountIndex: 0x0}, Signature: types.MultiSignature{IsSr25519: true, AsSr25519: types.Signature{0xc0, 0x42, 0x19, 0x5f, 0x93, 0x25, 0xd, 0x3e, 0xda, 0xa2, 0xe4, 0xa4, 0x2d, 0xcf, 0x4e, 0x41, 0xc1, 0x6c, 0xa7, 0x1c, 0xfc, 0x3a, 0x2b, 0x23, 0x99, 0x8a, 0xd4, 0xec, 0x97, 0x4f, 0x8b, 0x1a, 0xcd, 0xcd, 0xad, 0x97, 0xd1, 0x4b, 0x6d, 0xf5, 0xcb, 0x89, 0x6, 0xff, 0x61, 0xc8, 0x92, 0x17, 0x96, 0x54, 0xa5, 0xec, 0xcc, 0xb, 0x66, 0x85, 0xf6, 0xc1, 0x7f, 0xed, 0x49, 0x21, 0x94, 0x0}}, Era: types.ExtrinsicEra{IsImmortalEra: true, IsMortalEra: false, AsMortalEra: types.MortalEra{First: 0x0, Second: 0x0}}, Nonce: 0x1, Tip: 0x0}, Method: types.Call{CallIndex: types.CallIndex{SectionIndex: 0x6, MethodIndex: 0x0}, Args: types.Args{0xff, 0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48, 0xe5, 0x6c}}} //nolint:lll,dupl
27+
ext := types.Extrinsic{Version: 0x84, Signature: types.ExtrinsicSignatureV4{Signer: types.Address{IsAccountID: true, AsAccountID: types.AccountID{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, IsAccountIndex: false, AsAccountIndex: 0x0}, Signature: types.MultiSignature{IsSr25519: true, AsSr25519: types.Signature{0xc0, 0x42, 0x19, 0x5f, 0x93, 0x25, 0xd, 0x3e, 0xda, 0xa2, 0xe4, 0xa4, 0x2d, 0xcf, 0x4e, 0x41, 0xc1, 0x6c, 0xa7, 0x1c, 0xfc, 0x3a, 0x2b, 0x23, 0x99, 0x8a, 0xd4, 0xec, 0x97, 0x4f, 0x8b, 0x1a, 0xcd, 0xcd, 0xad, 0x97, 0xd1, 0x4b, 0x6d, 0xf5, 0xcb, 0x89, 0x6, 0xff, 0x61, 0xc8, 0x92, 0x17, 0x96, 0x54, 0xa5, 0xec, 0xcc, 0xb, 0x66, 0x85, 0xf6, 0xc1, 0x7f, 0xed, 0x49, 0x21, 0x94, 0x0}}, Era: types.ExtrinsicEra{IsImmortalEra: true, IsMortalEra: false, AsMortalEra: types.MortalEra{First: 0x0, Second: 0x0}}, Nonce: types.NewUCompactFromUInt(0x1), Tip: types.NewUCompactFromUInt(0x0)}, Method: types.Call{CallIndex: types.CallIndex{SectionIndex: 0x6, MethodIndex: 0x0}, Args: types.Args{0xff, 0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48, 0xe5, 0x6c}}} //nolint:lll,dupl
2828
res, err := author.SubmitExtrinsic(ext)
2929
assert.NoError(t, err)
3030
hex, err := types.Hex(res)

scale/codec.go

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"log"
2424
"math"
25+
"math/big"
2526
"reflect"
2627
)
2728

@@ -70,47 +71,50 @@ func (pe Encoder) PushByte(b byte) error {
7071
// zL zL zL 10 / zM zM zM zL / zM zM zM zM / zH zH zH zM (2**14 ... 2**30 - 1) (u16, u32) low LMMH high
7172
// nn nn nn 11 [ / zz zz zz zz ]{4 + n} (2**30 ... 2**536 - 1) (u32, u64, u128, U256, U512, U520) straight LE-encoded
7273
// Rust implementation: see impl<'a> Encode for CompactRef<'a, u64>
73-
func (pe Encoder) EncodeUintCompact(v uint64) error {
74-
75-
// TODO: handle numbers wider than 64 bits (byte slices?)
76-
// Currently, Rust implementation only seems to support u128
74+
func (pe Encoder) EncodeUintCompact(v big.Int) error {
75+
if v.Sign() == -1 {
76+
return errors.New("Assertion error: EncodeUintCompact cannot process negative numbers")
77+
}
7778

78-
if v < 1<<30 {
79-
if v < 1<<6 {
80-
err := pe.PushByte(byte(v) << 2)
81-
if err != nil {
82-
return err
83-
}
84-
} else if v < 1<<14 {
85-
err := binary.Write(pe.writer, binary.LittleEndian, uint16(v<<2)+1)
86-
if err != nil {
87-
return err
88-
}
89-
} else {
90-
err := binary.Write(pe.writer, binary.LittleEndian, uint32(v<<2)+2)
91-
if err != nil {
92-
return err
79+
if v.IsUint64() {
80+
if v.Uint64() < 1<<30 {
81+
if v.Uint64() < 1<<6 {
82+
err := pe.PushByte(byte(v.Uint64()) << 2)
83+
if err != nil {
84+
return err
85+
}
86+
} else if v.Uint64() < 1<<14 {
87+
err := binary.Write(pe.writer, binary.LittleEndian, uint16(v.Uint64()<<2)+1)
88+
if err != nil {
89+
return err
90+
}
91+
} else {
92+
err := binary.Write(pe.writer, binary.LittleEndian, uint32(v.Uint64()<<2)+2)
93+
if err != nil {
94+
return err
95+
}
9396
}
97+
return nil
9498
}
95-
return nil
9699
}
97100

98-
n := byte(0)
99-
limit := uint64(1 << 32)
100-
for v >= limit && limit > 256 { // when overflows, limit will be < 256
101-
n++
102-
limit <<= 8
101+
numBytes := len(v.Bytes())
102+
if numBytes > 255 {
103+
return errors.New("Assertion error: numBytes>255 exeeds allowed for length prefix")
103104
}
104-
if n > 4 {
105-
return errors.New("Assertion error: n>4 needed to compact-encode uint64")
105+
topSixBits := uint8(numBytes - 4)
106+
lengthByte := topSixBits<<2 + 3
107+
108+
if topSixBits > 63 {
109+
return errors.New("Assertion error: n<=63 needed to compact-encode substrate unsigned big integer")
106110
}
107-
err := pe.PushByte((n << 2) + 3)
111+
err := pe.PushByte(lengthByte)
108112
if err != nil {
109113
return err
110114
}
111-
buf := make([]byte, 8)
112-
binary.LittleEndian.PutUint64(buf, v)
113-
err = pe.Write(buf[:4+n])
115+
buf := v.Bytes()
116+
Reverse(buf)
117+
err = pe.Write(buf)
114118
if err != nil {
115119
return err
116120
}
@@ -199,7 +203,7 @@ func (pe Encoder) Encode(value interface{}) error {
199203
if len64 > math.MaxUint32 {
200204
return errors.New("Attempted to serialize a collection with too many elements.")
201205
}
202-
err := pe.EncodeUintCompact(len64)
206+
err := pe.EncodeUintCompact(*big.NewInt(0).SetUint64(len64))
203207
if err != nil {
204208
return err
205209
}
@@ -419,13 +423,13 @@ func (pd Decoder) DecodeIntoReflectValue(target reflect.Value) error {
419423
// Slices: first compact-encode length, then each item individually
420424
case reflect.Slice:
421425
codedLen64, _ := pd.DecodeUintCompact()
422-
if codedLen64 > math.MaxUint32 {
426+
if codedLen64.Uint64() > math.MaxUint32 {
423427
return errors.New("Encoded array length is higher than allowed by the protocol (32-bit unsigned integer)")
424428
}
425-
if codedLen64 > uint64(maxInt) {
429+
if codedLen64.Uint64() > uint64(maxInt) {
426430
return errors.New("Encoded array length is higher than allowed by the platform")
427431
}
428-
codedLen := int(codedLen64)
432+
codedLen := int(codedLen64.Uint64())
429433
targetLen := target.Len()
430434
if codedLen != targetLen {
431435
if int(codedLen) > target.Cap() {
@@ -487,51 +491,60 @@ func (pd Decoder) DecodeIntoReflectValue(target reflect.Value) error {
487491
}
488492

489493
// DecodeUintCompact decodes a compact-encoded integer. See EncodeUintCompact method.
490-
func (pd Decoder) DecodeUintCompact() (uint64, error) {
494+
func (pd Decoder) DecodeUintCompact() (*big.Int, error) {
491495
b, _ := pd.ReadOneByte()
492496
mode := b & 3
493497
switch mode {
494498
case 0:
495499
// right shift to remove mode bits
496-
return uint64(b >> 2), nil
500+
return big.NewInt(0).SetUint64(uint64(b >> 2)), nil
497501
case 1:
498502
bb, err := pd.ReadOneByte()
499503
if err != nil {
500-
return 0, err
504+
return nil, err
501505
}
502506
r := uint64(bb)
503507
// * 2^6
504508
r <<= 6
505509
// right shift to remove mode bits and add to prev
506510
r += uint64(b >> 2)
507-
return r, nil
511+
return big.NewInt(0).SetUint64(r), nil
508512
case 2:
509513
// value = 32 bits + mode
510514
buf := make([]byte, 4)
511515
buf[0] = b
512516
err := pd.Read(buf[1:4])
513517
if err != nil {
514-
return 0, err
518+
return nil, err
515519
}
516520
// set the buffer in little endian order
517521
r := binary.LittleEndian.Uint32(buf)
518522
// remove the last 2 mode bits
519523
r >>= 2
520-
return uint64(r), nil
524+
return big.NewInt(0).SetUint64(uint64(r)) , nil
521525
case 3:
522526
// remove mode bits
523527
l := b >> 2
524-
if l > 4 {
525-
return 0, errors.New("Not supported: l>4 encountered when decoding a compact-encoded uint")
528+
529+
if l > 63 { // Max upper bound of 536 is (67 - 4)
530+
return nil, errors.New("Not supported: l>63 encountered when decoding a compact-encoded uint")
526531
}
527-
buf := make([]byte, 8)
528-
err := pd.Read(buf[:l+4])
532+
buf := make([]byte, l+4)
533+
err := pd.Read(buf)
529534
if err != nil {
530-
return 0, err
535+
return nil, err
531536
}
532-
return binary.LittleEndian.Uint64(buf), nil
537+
Reverse(buf)
538+
return new(big.Int).SetBytes(buf), nil
533539
default:
534-
return 0, errors.New("Code should be unreachable")
540+
return nil, errors.New("Code should be unreachable")
541+
}
542+
}
543+
544+
// Reverse reverses bytes in place (manipulates the underlying array)
545+
func Reverse(b []byte) {
546+
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
547+
b[i], b[j] = b[j], b[i]
535548
}
536549
}
537550

scale/codec_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bytes"
1919
"fmt"
2020
"math"
21+
"math/big"
2122
"reflect"
2223
"strings"
2324
"testing"
@@ -248,10 +249,11 @@ func TestCompactIntegersEncodedAsExpected(t *testing.T) {
248249
math.MaxUint64: "13 ff ff ff ff ff ff ff ff"}
249250
for value, expectedHex := range tests {
250251
var buffer = bytes.Buffer{}
251-
err := Encoder{writer: &buffer}.EncodeUintCompact(value)
252+
valueBig := new(big.Int).SetUint64(value)
253+
err := Encoder{writer: &buffer}.EncodeUintCompact(*valueBig)
252254
assert.NoError(t, err)
253255
assertEqual(t, hexify(buffer.Bytes()), expectedHex)
254256
decoded, _ := Decoder{reader: &buffer}.DecodeUintCompact()
255-
assertEqual(t, decoded, value)
257+
assertEqual(t, decoded, big.NewInt(0).SetUint64(value))
256258
}
257259
}

teste2e/author_submit_and_watch_extrinsic_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestAuthor_SubmitAndWatchExtrinsic(t *testing.T) {
5353
panic(err)
5454
}
5555

56-
c, err := types.NewCall(meta, "Balances.transfer", bob, types.UCompact(6969))
56+
c, err := types.NewCall(meta, "Balances.transfer", bob, types.NewUCompactFromUInt(6969))
5757
if err != nil {
5858
panic(err)
5959
}
@@ -93,9 +93,9 @@ func TestAuthor_SubmitAndWatchExtrinsic(t *testing.T) {
9393
BlockHash: genesisHash, // BlockHash needs to == GenesisHash if era is immortal. // TODO: add an error?
9494
Era: era,
9595
GenesisHash: genesisHash,
96-
Nonce: types.UCompact(nonce),
96+
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
9797
SpecVersion: rv.SpecVersion,
98-
Tip: 0,
98+
Tip: types.NewUCompactFromUInt(0),
9999
}
100100

101101

teste2e/author_submit_extrinsic_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestChain_SubmitExtrinsic(t *testing.T) {
5252
panic(err)
5353
}
5454

55-
c, err := types.NewCall(meta, "Balances.transfer", bob, types.UCompact(6969))
55+
c, err := types.NewCall(meta, "Balances.transfer", bob, types.NewUCompactFromUInt(6969))
5656
if err != nil {
5757
panic(err)
5858
}
@@ -95,9 +95,9 @@ func TestChain_SubmitExtrinsic(t *testing.T) {
9595
BlockHash: genesisHash, // BlockHash needs to == GenesisHash if era is immortal. // TODO: add an error?
9696
Era: era,
9797
GenesisHash: genesisHash,
98-
Nonce: types.UCompact(nonce + i),
98+
Nonce: types.NewUCompactFromUInt(uint64(nonce + i)),
9999
SpecVersion: rv.SpecVersion,
100-
Tip: 0,
100+
Tip: types.NewUCompactFromUInt(0),
101101
}
102102

103103
extI := ext

types/event_record.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (e EventRecordsRaw) DecodeEventRecords(m *Metadata, t interface{}) error {
180180
log.Debug(fmt.Sprintf("found %v events", n))
181181

182182
// iterate over events
183-
for i := uint64(0); i < n; i++ {
183+
for i := uint64(0); i < n.Uint64(); i++ {
184184
log.Debug(fmt.Sprintf("decoding event #%v", i))
185185

186186
// decode Phase

types/event_record_test.go

Lines changed: 27 additions & 0 deletions
Large diffs are not rendered by default.

types/extrinsic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"io"
24+
"math/big"
2425
"strings"
2526

2627
"github.com/centrifuge/go-substrate-rpc-client/scale"
@@ -90,7 +91,7 @@ func (e *Extrinsic) UnmarshalJSON(bz []byte) error {
9091
if err != nil {
9192
return err
9293
}
93-
length := UCompact(len(dec))
94+
length := NewUCompactFromUInt(uint64(len(dec)))
9495
bprefix, err := EncodeToBytes(length)
9596
if err != nil {
9697
return err
@@ -234,7 +235,7 @@ func (e Extrinsic) Encode(encoder scale.Encoder) error {
234235

235236
// take the temporary buffer to determine length, write that as prefix
236237
eb := bb.Bytes()
237-
err = encoder.EncodeUintCompact(uint64(len(eb)))
238+
err = encoder.EncodeUintCompact(*big.NewInt(0).SetUint64(uint64(len(eb))))
238239
if err != nil {
239240
return err
240241
}

0 commit comments

Comments
 (0)