Skip to content

Commit

Permalink
add AssetID support to extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
onexie committed Apr 24, 2024
1 parent 5c18e99 commit f979695
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
12 changes: 5 additions & 7 deletions types/extrinsic_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (e *ExtrinsicPayloadV3) Decode(decoder scale.Decoder) error {

type ExtrinsicPayloadV4 struct {
ExtrinsicPayloadV3
AssetSuportflag bool // true if the extrinsic supports assetID
AssetID Option[U32]
TransactionVersion U32
}
Expand Down Expand Up @@ -133,13 +134,10 @@ func (e ExtrinsicPayloadV4) Encode(encoder scale.Encoder) error {
if err != nil {
return err
}
if e.AssetID.HasValue() {
ok, assetID := e.AssetID.Unwrap()
if ok {
err = encoder.Encode(assetID)
if err != nil {
return err
}
if e.AssetSuportflag {
err = encoder.Encode(e.AssetID)
if err != nil {
return err
}
}
err = encoder.Encode(e.SpecVersion)
Expand Down
45 changes: 39 additions & 6 deletions types/extrinsic_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package types

import "github.com/dcnetio/go-substrate-rpc-client/v4/scale"

type ExtrinsicSignatureV3 struct {
Signer Address
Signature Signature
Expand All @@ -34,12 +36,13 @@ type ExtrinsicSignatureV4 struct {

// ExtrinsicEthSignatureV4 is the signature type for pallet-ethereum compatibility
type ExtrinsicEthSignatureV4 struct {
Signer [20]byte
Signature EcdsaSignature // MultiSignature
Era ExtrinsicEra // extra via system::CheckEra
Nonce UCompact // extra via system::CheckNonce (Compact<Index> where Index is u32))
Tip UCompact // extra via balances::TakeFees (Compact<Balance> where Balance is u128))
// AssetID Option[U32]
Signer [20]byte
Signature EcdsaSignature // MultiSignature
Era ExtrinsicEra // extra via system::CheckEra
Nonce UCompact // extra via system::CheckNonce (Compact<Index> where Index is u32))
Tip UCompact // extra via balances::TakeFees (Compact<Balance> where Balance is u128))
AssertSuportflag bool // if true, the extrinsic is signed with Assert support
AssetID Option[U32] // extra via pallet-ethereum::CheckAssetID
}

type SignatureOptions struct {
Expand All @@ -51,3 +54,33 @@ type SignatureOptions struct {
BlockHash Hash // additional via system::CheckEra
TransactionVersion U32 // additional via system::CheckTxVersion
}

func (es ExtrinsicEthSignatureV4) Encode(encoder scale.Encoder) error {
err := encoder.Encode(es.Signer)
if err != nil {
return err
}
err = encoder.Encode(es.Signature)
if err != nil {
return err
}
err = encoder.Encode(es.Era)
if err != nil {
return err
}
err = encoder.Encode(es.Nonce)
if err != nil {
return err
}
err = encoder.Encode(es.Tip)
if err != nil {
return err
}
if es.AssertSuportflag {
err = encoder.Encode(es.AssetID)
if err != nil {
return err
}
}
return nil
}

0 comments on commit f979695

Please sign in to comment.