From 5c4d5e03fb9db11c909b921e906ae8afb996772c Mon Sep 17 00:00:00 2001 From: freehere107 Date: Fri, 5 Jan 2024 10:13:44 +0800 Subject: [PATCH] ScaleDecoderOption Add AdditionalCheck opt --- extrinsic.go | 7 +++++-- types/base.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extrinsic.go b/extrinsic.go index 6785333..188a9d6 100644 --- a/extrinsic.go +++ b/extrinsic.go @@ -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 @@ -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) } @@ -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 @@ -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) { @@ -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) } } diff --git a/types/base.go b/types/base.go index 0bda9e6..62997bc 100644 --- a/types/base.go +++ b/types/base.go @@ -21,6 +21,7 @@ type ScaleDecoderOption struct { Metadata *MetadataStruct FixedLength int SignedExtensions []SignedExtension `json:"signed_extensions"` + AdditionalCheck []string TypeName string recursiveTime int }