Skip to content

Commit

Permalink
ScaleDecoderOption Add AdditionalCheck opt
Browse files Browse the repository at this point in the history
  • Loading branch information
freehere107 committed Jan 5, 2024
1 parent ca31497 commit 5c4d5e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ExtrinsicDecoder struct {
Params []ExtrinsicParam `json:"params"`
Metadata *scaleType.MetadataStruct
SignedExtensions []scaleType.SignedExtension `json:"signed_extensions"`
AdditionalCheck []string
}

// https://github.com/polkadot-js/api/blob/master/packages/types/src/extrinsic/signedExtensions/index.ts#L24
Expand All @@ -55,6 +56,7 @@ func (e *ExtrinsicDecoder) Init(data scaleBytes.ScaleBytes, option *scaleType.Sc
e.Params = []ExtrinsicParam{}
e.Metadata = option.Metadata
e.SignedExtensions = option.SignedExtensions
e.AdditionalCheck = option.AdditionalCheck
e.ScaleDecoder.Init(data, option)
}

Expand Down Expand Up @@ -114,7 +116,7 @@ func (e *ExtrinsicDecoder) Process() {
if e.VersionInfo == "04" || e.VersionInfo == "84" {
if e.ContainsTransaction {
// Address
result.Signer = e.ProcessAndUpdateData(utiles.TrueOrElse(e.Metadata.MetadataVersion >= 14 && scaleType.HasReg("ExtrinsicSigner"), "ExtrinsicSigner", "Address"))
result.Signer = e.ProcessAndUpdateData(utiles.TrueOrElse(e.Metadata.MetadataVersion >= 14 && scaleType.HasReg("ExtrinsicSigner"), "ExtrinsicSigner", "multiAddress"))
switch v := result.Signer.(type) {
case string:
e.Address = v
Expand All @@ -125,6 +127,7 @@ func (e *ExtrinsicDecoder) Process() {
e.Address = value
}
}
utiles.Debug(result.Signer)
// ExtrinsicSignature
result.SignatureRaw = e.ProcessAndUpdateData("ExtrinsicSignature")
switch v := result.SignatureRaw.(type) {
Expand Down Expand Up @@ -157,7 +160,7 @@ func (e *ExtrinsicDecoder) Process() {
} else {
if e.Metadata.MetadataVersion >= 14 {
for _, ext := range e.Metadata.Extrinsic.SignedExtensions {
if enable, ok := signedExts[ext.Identifier]; ok && enable {
if enable := signedExts[ext.Identifier]; enable || utiles.SliceIndex(ext.Identifier, e.AdditionalCheck) >= 0 {
result.SignedExtensions[ext.Identifier] = e.ProcessAndUpdateData(ext.TypeString)
}
}
Expand Down
1 change: 1 addition & 0 deletions types/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ScaleDecoderOption struct {
Metadata *MetadataStruct
FixedLength int
SignedExtensions []SignedExtension `json:"signed_extensions"`
AdditionalCheck []string
TypeName string
recursiveTime int
}
Expand Down

0 comments on commit 5c4d5e0

Please sign in to comment.