Skip to content

Fix sign opts #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions chains/substrate/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
"context"
"fmt"
"math/big"
"strings"
"sync"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v4/rpc/author"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
"github.com/centrifuge/go-substrate-rpc-client/v4/hash"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic/extensions"
"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/chains/substrate/connection"
"github.com/sygmaprotocol/sygma-core/chains/substrate/events"
"encoding/hex"
)

type SubstrateClient struct {
Expand Down Expand Up @@ -74,14 +77,14 @@
sub, err := c.submitAndWatchExtrinsic(
&ext,
&meta,
extrinsic.WithEra(types.ExtrinsicEra{IsImmortalEra: false}, c.Conn.GenesisHash),
extrinsic.WithGenesisHash(c.Conn.GenesisHash),
extrinsic.WithEra(types.ExtrinsicEra{IsImmortalEra: true}, c.Conn.GenesisHash),
extrinsic.WithNonce(types.NewUCompactFromUInt(uint64(nonce))),
extrinsic.WithSpecVersion(rv.SpecVersion),
extrinsic.WithTip(types.NewUCompactFromUInt(c.tip)),
extrinsic.WithMetadataMode(extensions.CheckMetadataModeDisabled),

Check failure on line 83 in chains/substrate/client/client.go

View workflow job for this annotation

GitHub Actions / linter-check

not enough arguments in call to extrinsic.WithMetadataMode
extrinsic.WithSpecVersion(rv.SpecVersion),
extrinsic.WithTransactionVersion(rv.TransactionVersion),
extrinsic.WithMetadataMode(extensions.CheckMetadataModeDisabled, extensions.CheckMetadataHash{Hash: types.NewEmptyOption[types.H256]()}),
extrinsic.WithAssetID(types.NewEmptyOption[types.AssetID]()),
extrinsic.WithGenesisHash(c.Conn.GenesisHash),
extrinsic.WithMetadataHash(extensions.CheckMetadataHash{Hash: types.NewEmptyOption[types.H256]()}),

Check failure on line 87 in chains/substrate/client/client.go

View workflow job for this annotation

GitHub Actions / linter-check

undefined: extrinsic.WithMetadataHash (typecheck)
)
if err != nil {
return types.Hash{}, nil, fmt.Errorf("submission of extrinsic failed: %w", err)
Expand All @@ -92,11 +95,28 @@
return types.Hash{}, nil, err
}

hash, err := types.NewHashFromHexString(enc)
// Decode the hex string to get the raw extrinsic bytes
var extBytes []byte
if strings.HasPrefix(enc, "0x") {
extBytes, err = hex.DecodeString(enc[2:])
} else {
extBytes, err = hex.DecodeString(enc)
}
if err != nil {
return types.Hash{}, nil, err
return types.Hash{}, nil, fmt.Errorf("failed to decode extrinsic hex: %w", err)
}

// Create Blake2b-256 hash of the extrinsic bytes
hasher, err := hash.NewBlake2b256(nil)
if err != nil {
return types.Hash{}, nil, fmt.Errorf("failed to create hasher: %w", err)
}
hasher.Write(extBytes)
hashBytes := hasher.Sum(nil)

// Create a new Hash from the hash bytes
hash := types.NewHash(hashBytes)

log.Info().Str("extrinsic", hash.Hex()).Msgf("Extrinsic call submitted... method %s, sender %s, nonce %d", method, c.key.Address, nonce)
c.nonce = nonce + 1

Expand Down
Loading