@@ -7,18 +7,21 @@ import (
7
7
"context"
8
8
"fmt"
9
9
"math/big"
10
+ "strings"
10
11
"sync"
11
12
"time"
12
13
13
14
"github.com/centrifuge/go-substrate-rpc-client/v4/rpc/author"
14
15
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
16
+ "github.com/centrifuge/go-substrate-rpc-client/v4/hash"
15
17
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
16
18
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
17
19
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
18
20
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic/extensions"
19
21
"github.com/rs/zerolog/log"
20
22
"github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
21
23
"github.com/sygmaprotocol/sygma-core/chains/substrate/events"
24
+ "encoding/hex"
22
25
)
23
26
24
27
type SubstrateClient struct {
@@ -74,14 +77,14 @@ func (c *SubstrateClient) Transact(method string, args ...interface{}) (types.Ha
74
77
sub , err := c .submitAndWatchExtrinsic (
75
78
& ext ,
76
79
& meta ,
77
- extrinsic .WithEra (types.ExtrinsicEra {IsImmortalEra : false }, c .Conn .GenesisHash ),
78
- extrinsic .WithGenesisHash (c .Conn .GenesisHash ),
80
+ extrinsic .WithEra (types.ExtrinsicEra {IsImmortalEra : true }, c .Conn .GenesisHash ),
79
81
extrinsic .WithNonce (types .NewUCompactFromUInt (uint64 (nonce ))),
80
- extrinsic .WithSpecVersion (rv .SpecVersion ),
81
82
extrinsic .WithTip (types .NewUCompactFromUInt (c .tip )),
83
+ extrinsic .WithMetadataMode (extensions .CheckMetadataModeDisabled ),
84
+ extrinsic .WithSpecVersion (rv .SpecVersion ),
82
85
extrinsic .WithTransactionVersion (rv .TransactionVersion ),
83
- extrinsic .WithMetadataMode ( extensions . CheckMetadataModeDisabled , extensions. CheckMetadataHash { Hash : types . NewEmptyOption [types. H256 ]()} ),
84
- extrinsic .WithAssetID ( types .NewEmptyOption [types.AssetID ]()),
86
+ extrinsic .WithGenesisHash ( c . Conn . GenesisHash ),
87
+ extrinsic .WithMetadataHash (extensions. CheckMetadataHash { Hash : types .NewEmptyOption [types.H256 ]()} ),
85
88
)
86
89
if err != nil {
87
90
return types.Hash {}, nil , fmt .Errorf ("submission of extrinsic failed: %w" , err )
@@ -92,11 +95,28 @@ func (c *SubstrateClient) Transact(method string, args ...interface{}) (types.Ha
92
95
return types.Hash {}, nil , err
93
96
}
94
97
95
- hash , err := types .NewHashFromHexString (enc )
98
+ // Decode the hex string to get the raw extrinsic bytes
99
+ var extBytes []byte
100
+ if strings .HasPrefix (enc , "0x" ) {
101
+ extBytes , err = hex .DecodeString (enc [2 :])
102
+ } else {
103
+ extBytes , err = hex .DecodeString (enc )
104
+ }
96
105
if err != nil {
97
- return types.Hash {}, nil , err
106
+ return types.Hash {}, nil , fmt . Errorf ( "failed to decode extrinsic hex: %w" , err )
98
107
}
99
108
109
+ // Create Blake2b-256 hash of the extrinsic bytes
110
+ hasher , err := hash .NewBlake2b256 (nil )
111
+ if err != nil {
112
+ return types.Hash {}, nil , fmt .Errorf ("failed to create hasher: %w" , err )
113
+ }
114
+ hasher .Write (extBytes )
115
+ hashBytes := hasher .Sum (nil )
116
+
117
+ // Create a new Hash from the hash bytes
118
+ hash := types .NewHash (hashBytes )
119
+
100
120
log .Info ().Str ("extrinsic" , hash .Hex ()).Msgf ("Extrinsic call submitted... method %s, sender %s, nonce %d" , method , c .key .Address , nonce )
101
121
c .nonce = nonce + 1
102
122
0 commit comments