Skip to content

Commit 1063d49

Browse files
authored
Fix sign opts (#42)
1 parent c66e0ae commit 1063d49

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

chains/substrate/client/client.go

+27-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import (
77
"context"
88
"fmt"
99
"math/big"
10+
"strings"
1011
"sync"
1112
"time"
1213

1314
"github.com/centrifuge/go-substrate-rpc-client/v4/rpc/author"
1415
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
16+
"github.com/centrifuge/go-substrate-rpc-client/v4/hash"
1517
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
1618
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
1719
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
1820
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic/extensions"
1921
"github.com/rs/zerolog/log"
2022
"github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
2123
"github.com/sygmaprotocol/sygma-core/chains/substrate/events"
24+
"encoding/hex"
2225
)
2326

2427
type SubstrateClient struct {
@@ -74,14 +77,14 @@ func (c *SubstrateClient) Transact(method string, args ...interface{}) (types.Ha
7477
sub, err := c.submitAndWatchExtrinsic(
7578
&ext,
7679
&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),
7981
extrinsic.WithNonce(types.NewUCompactFromUInt(uint64(nonce))),
80-
extrinsic.WithSpecVersion(rv.SpecVersion),
8182
extrinsic.WithTip(types.NewUCompactFromUInt(c.tip)),
83+
extrinsic.WithMetadataMode(extensions.CheckMetadataModeDisabled),
84+
extrinsic.WithSpecVersion(rv.SpecVersion),
8285
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]()}),
8588
)
8689
if err != nil {
8790
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
9295
return types.Hash{}, nil, err
9396
}
9497

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+
}
96105
if err != nil {
97-
return types.Hash{}, nil, err
106+
return types.Hash{}, nil, fmt.Errorf("failed to decode extrinsic hex: %w", err)
98107
}
99108

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+
100120
log.Info().Str("extrinsic", hash.Hex()).Msgf("Extrinsic call submitted... method %s, sender %s, nonce %d", method, c.key.Address, nonce)
101121
c.nonce = nonce + 1
102122

0 commit comments

Comments
 (0)