@@ -16,6 +16,53 @@ import (
16
16
"golang.org/x/crypto/blake2b"
17
17
)
18
18
19
+ func CreateExtrinsic (api * SubstrateAPI , ext_call string , keyring signature.KeyringPair , AppID int , arg ... interface {}) (extrinsic.Extrinsic , error ) {
20
+ meta , err := api .RPC .State .GetMetadataLatest ()
21
+ if err != nil {
22
+ return extrinsic.Extrinsic {}, err
23
+ }
24
+ call , err := types .NewCall (meta , ext_call , arg ... )
25
+ if err != nil {
26
+ return extrinsic.Extrinsic {}, err
27
+ }
28
+ ext := extrinsic .NewExtrinsic (call )
29
+ genesisHash , err := api .RPC .Chain .GetBlockHash (0 )
30
+ if err != nil {
31
+ return extrinsic.Extrinsic {}, err
32
+ }
33
+ rv , err := api .RPC .State .GetRuntimeVersionLatest ()
34
+ if err != nil {
35
+ return extrinsic.Extrinsic {}, err
36
+ }
37
+ key , err := types .CreateStorageKey (meta , "System" , "Account" , keyring .PublicKey )
38
+ if err != nil {
39
+ return extrinsic.Extrinsic {}, err
40
+ }
41
+
42
+ var accountInfo types.AccountInfo
43
+ ok , err := api .RPC .State .GetStorageLatest (key , & accountInfo )
44
+ if err != nil || ! ok {
45
+ return extrinsic.Extrinsic {}, err
46
+ }
47
+ nonce := uint32 (accountInfo .Nonce )
48
+ options := extrinsic.SignatureOptions {
49
+ BlockHash : genesisHash ,
50
+ Era : extrinsic.ExtrinsicEra {IsMortalEra : false },
51
+ GenesisHash : genesisHash ,
52
+ Nonce : types .NewUCompactFromUInt (uint64 (nonce )),
53
+ SpecVersion : rv .SpecVersion ,
54
+ Tip : types .NewUCompactFromUInt (100 ),
55
+ AppID : types .NewUCompactFromUInt (uint64 (AppID )),
56
+ TransactionVersion : rv .TransactionVersion ,
57
+ }
58
+
59
+ err = ext .Sign (keyring , options )
60
+ if err != nil {
61
+ panic (fmt .Sprintf ("cannot sign:%v" , err ))
62
+ }
63
+ return ext , nil
64
+ }
65
+
19
66
func NewExtrinsic (api * SubstrateAPI , ext_call string , keyring signature.KeyringPair , AppID int , arg ... interface {}) (types.Hash , error ) {
20
67
meta , err := api .RPC .State .GetMetadataLatest ()
21
68
if err != nil {
0 commit comments