Skip to content

Commit 03102b8

Browse files
committed
Add new events + types (#111)
* Revert "Add ExtrinsicSignatureV5 (#68)" This reverts commit 461cf42. * Added new events + types * Add tests * Remove fmt * typo
1 parent 84ed6a9 commit 03102b8

10 files changed

Lines changed: 270 additions & 21 deletions

hash/blake2b.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ func NewBlake2b128(k []byte) (hash.Hash, error) {
7676
func NewBlake2b256(k []byte) (hash.Hash, error) {
7777
return blake2b.New256(k)
7878
}
79+
80+
// NewBlake2b512 returns blake2b-512 hasher
81+
func NewBlake2b512(k []byte) (hash.Hash, error) {
82+
return blake2b.New512(k)
83+
}

hash/blake2b_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,19 @@ func TestBlake2_128Concat(t *testing.T) {
3636
h.Reset()
3737
assert.Equal(t, 16, h.Size())
3838
}
39+
40+
func TestBlake2b_512(t *testing.T) {
41+
h, err := NewBlake2b512(nil)
42+
assert.NoError(t, err)
43+
n, err := h.Write([]byte("abc"))
44+
assert.NoError(t, err)
45+
assert.Equal(t, 3, n)
46+
assert.Equal(t, []byte{
47+
0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0xd, 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9, 0x4c, 0x21, 0x2f,
48+
0x14, 0x68, 0x5a, 0xc4, 0xb7, 0x4b, 0x12, 0xbb, 0x6f, 0xdb, 0xff, 0xa2, 0xd1, 0x7d, 0x87, 0xc5, 0x39, 0x2a, 0xab,
49+
0x79, 0x2d, 0xc2, 0x52, 0xd5, 0xde, 0x45, 0x33, 0xcc, 0x95, 0x18, 0xd3, 0x8a, 0xa8, 0xdb, 0xf1, 0x92, 0x5a, 0xb9,
50+
0x23, 0x86, 0xed, 0xd4, 0x0, 0x99, 0x23,
51+
}, h.Sum(nil))
52+
assert.Equal(t, 128, h.BlockSize())
53+
assert.Equal(t, 64, h.Size())
54+
}

main_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func Example_makeASimpleTransfer() {
241241
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
242242
SpecVersion: rv.SpecVersion,
243243
Tip: types.NewUCompactFromUInt(0),
244+
TransactionVersion: rv.TransactionVersion,
244245
}
245246

246247
// Sign the transaction using Alice's default account
@@ -375,7 +376,7 @@ func Example_displaySystemEvents() {
375376
fmt.Printf("\tSystem:ExtrinsicSuccess:: (phase=%#v)\n", e.Phase)
376377
}
377378
for _, e := range events.System_ExtrinsicFailed {
378-
fmt.Printf("\tSystem:ErtrinsicFailed:: (phase=%#v)\n", e.Phase)
379+
fmt.Printf("\tSystem:ExtrinsicFailed:: (phase=%#v)\n", e.Phase)
379380
fmt.Printf("\t\t%v\n", e.DispatchError)
380381
}
381382
for _, e := range events.System_CodeUpdated {
@@ -422,9 +423,6 @@ func Example_transactionWithEvents() {
422423

423424
// Create the extrinsic
424425
ext := types.NewExtrinsic(c)
425-
if err != nil {
426-
panic(err)
427-
}
428426

429427
genesisHash, err := api.RPC.Chain.GetBlockHash(0)
430428
if err != nil {
@@ -457,6 +455,7 @@ func Example_transactionWithEvents() {
457455
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
458456
SpecVersion: rv.SpecVersion,
459457
Tip: types.NewUCompactFromUInt(0),
458+
TransactionVersion: rv.TransactionVersion,
460459
}
461460

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

teste2e/author_submit_and_watch_extrinsic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestAuthor_SubmitAndWatchExtrinsic(t *testing.T) {
9696
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
9797
SpecVersion: rv.SpecVersion,
9898
Tip: types.NewUCompactFromUInt(0),
99-
TransactionVersion: 1,
99+
TransactionVersion: rv.TransactionVersion,
100100
}
101101

102102
err = ext.Sign(from, o)

teste2e/author_submit_extrinsic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestChain_SubmitExtrinsic(t *testing.T) {
139139
Nonce: types.NewUCompactFromUInt(uint64(nonce + i)),
140140
SpecVersion: rv.SpecVersion,
141141
Tip: types.NewUCompactFromUInt(0),
142-
TransactionVersion: 1,
142+
TransactionVersion: rv.TransactionVersion,
143143
}
144144

145145
extI := ext

types/address_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,26 @@ import (
2020
"encoding/binary"
2121
"testing"
2222

23+
"github.com/btcsuite/btcutil/base58"
24+
"github.com/centrifuge/go-substrate-rpc-client/hash"
2325
. "github.com/centrifuge/go-substrate-rpc-client/types"
26+
"github.com/stretchr/testify/assert"
2427
)
2528

29+
func TestChecksum(t *testing.T) {
30+
//verify checksum from ss58
31+
contextPrefix := []byte("SS58PRE")
32+
ss58d := base58.Decode("4ecQzsMCwbJXu6Cad597T7gZx1MTZWQi8jZZC2DmsQq72knj")
33+
assert.Equal(t, uint8(36), ss58d[0]) // Centrifuge network version check
34+
noSum := ss58d[:len(ss58d)-2]
35+
all := append(contextPrefix, noSum...)
36+
checksum, err := hash.NewBlake2b512(nil)
37+
assert.NoError(t, err)
38+
checksum.Write(all)
39+
res := checksum.Sum(nil)
40+
assert.Equal(t, ss58d[len(ss58d)-2:], res[:2]) // Verified checksum
41+
}
42+
2643
func TestAddress_EncodeDecode(t *testing.T) {
2744
assertRoundtrip(t, NewAddressFromAccountID([]byte{128, 42}))
2845
assertRoundtrip(t, NewAddressFromAccountIndex(421))

types/event_record.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type EventRecords struct {
111111
Democracy_PreimageMissing []EventDemocracyPreimageMissing //nolint:stylecheck,golint
112112
Democracy_PreimageReaped []EventDemocracyPreimageReaped //nolint:stylecheck,golint
113113
Democracy_Unlocked []EventDemocracyUnlocked //nolint:stylecheck,golint
114+
Democracy_Blacklisted []EventDemocracyBlacklisted //nolint:stylecheck,golint
114115
Council_Proposed []EventCollectiveProposed //nolint:stylecheck,golint
115116
Council_Voted []EventCollectiveProposed //nolint:stylecheck,golint
116117
Council_Approved []EventCollectiveApproved //nolint:stylecheck,golint
@@ -125,8 +126,15 @@ type EventRecords struct {
125126
TechnicalCommittee_Executed []EventTechnicalCommitteeExecuted //nolint:stylecheck,golint
126127
TechnicalCommittee_MemberExecuted []EventTechnicalCommitteeMemberExecuted //nolint:stylecheck,golint
127128
TechnicalCommittee_Closed []EventTechnicalCommitteeClosed //nolint:stylecheck,golint
129+
TechnicalMembership_MemberAdded []EventTechnicalMembershipMemberAdded //nolint:stylecheck,golint
130+
TechnicalMembership_MemberRemoved []EventTechnicalMembershipMemberRemoved //nolint:stylecheck,golint
131+
TechnicalMembership_MembersSwapped []EventTechnicalMembershipMembersSwapped //nolint:stylecheck,golint
132+
TechnicalMembership_MembersReset []EventTechnicalMembershipMembersReset //nolint:stylecheck,golint
133+
TechnicalMembership_KeyChanged []EventTechnicalMembershipKeyChanged //nolint:stylecheck,golint
134+
TechnicalMembership_Dummy []EventTechnicalMembershipDummy //nolint:stylecheck,golint
128135
Elections_NewTerm []EventElectionsNewTerm //nolint:stylecheck,golint
129136
Elections_EmptyTerm []EventElectionsEmptyTerm //nolint:stylecheck,golint
137+
Elections_ElectionError []EventElectionsElectionError //nolint:stylecheck,golint
130138
Elections_MemberKicked []EventElectionsMemberKicked //nolint:stylecheck,golint
131139
Elections_MemberRenounced []EventElectionsMemberRenounced //nolint:stylecheck,golint
132140
Elections_VoterReported []EventElectionsVoterReported //nolint:stylecheck,golint
@@ -169,6 +177,7 @@ type EventRecords struct {
169177
Scheduler_Dispatched []EventSchedulerDispatched //nolint:stylecheck,golint
170178
Proxy_ProxyExecuted []EventProxyProxyExecuted //nolint:stylecheck,golint
171179
Proxy_AnonymousCreated []EventProxyAnonymousCreated //nolint:stylecheck,golint
180+
Proxy_Announced []EventProxyAnnounced //nolint:stylecheck,golint
172181
Sudo_Sudid []EventSudoSudid //nolint:stylecheck,golint
173182
Sudo_KeyChanged []EventSudoKeyChanged //nolint:stylecheck,golint
174183
Sudo_SudoAsDone []EventSudoAsDone //nolint:stylecheck,golint
@@ -183,6 +192,13 @@ type EventRecords struct {
183192
Treasury_TipClosing []EventTreasuryTipClosing //nolint:stylecheck,golint
184193
Treasury_TipClosed []EventTreasuryTipClosed //nolint:stylecheck,golint
185194
Treasury_TipRetracted []EventTreasuryTipRetracted //nolint:stylecheck,golint
195+
Treasury_BountyProposed []EventTreasuryBountyProposed //nolint:stylecheck,golint
196+
Treasury_BountyRejected []EventTreasuryBountyRejected //nolint:stylecheck,golint
197+
Treasury_BountyBecameActive []EventTreasuryBountyBecameActive //nolint:stylecheck,golint
198+
Treasury_BountyAwarded []EventTreasuryBountyAwarded //nolint:stylecheck,golint
199+
Treasury_BountyClaimed []EventTreasuryBountyClaimed //nolint:stylecheck,golint
200+
Treasury_BountyCanceled []EventTreasuryBountyCanceled //nolint:stylecheck,golint
201+
Treasury_BountyExtended []EventTreasuryBountyExtended //nolint:stylecheck,golint
186202
Contracts_Instantiated []EventContractsInstantiated //nolint:stylecheck,golint
187203
Contracts_Evicted []EventContractsEvicted //nolint:stylecheck,golint
188204
Contracts_Restored []EventContractsRestored //nolint:stylecheck,golint
@@ -191,10 +207,10 @@ type EventRecords struct {
191207
Contracts_ContractExecution []EventContractsContractExecution //nolint:stylecheck,golint
192208
Utility_BatchInterrupted []EventUtilityBatchInterrupted //nolint:stylecheck,golint
193209
Utility_BatchCompleted []EventUtilityBatchCompleted //nolint:stylecheck,golint
194-
Multisig_New []EventMultisigNewMultisig //nolint:stylecheck,golint
195-
Multisig_Approval []EventMultisigApproval //nolint:stylecheck,golint
196-
Multisig_Executed []EventMultisigExecuted //nolint:stylecheck,golint
197-
Multisig_Cancelled []EventMultisigCancelled //nolint:stylecheck,golint
210+
Multisig_NewMultisig []EventMultisigNewMultisig //nolint:stylecheck,golint
211+
Multisig_MultisigApproval []EventMultisigApproval //nolint:stylecheck,golint
212+
Multisig_MultisigExecuted []EventMultisigExecuted //nolint:stylecheck,golint
213+
Multisig_MultisigCancelled []EventMultisigCancelled //nolint:stylecheck,golint
198214
}
199215

200216
// DecodeEventRecords decodes the events records from an EventRecordRaw into a target t using the given Metadata m

0 commit comments

Comments
 (0)