Skip to content

Commit 2267cb7

Browse files
committed
Fix result not register
1 parent 4f4317f commit 2267cb7

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

contract/ABI_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package contract
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"testing"
66

77
"github.com/itering/scale.go/types"
88
"github.com/stretchr/testify/assert"
99
)
1010

1111
func Test_AbiParse(t *testing.T) {
12-
c, err := ioutil.ReadFile("metadata.json")
12+
c, err := os.ReadFile("metadata.json")
1313
assert.NoError(t, err)
1414

1515
abi, err := InitAbi(c)

event_test.go

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

tools/merge.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/customType.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func RegCustomTypes(registry map[string]source.TypeStruct) {
5555
if explainedType, ok := registry[typeString]; ok {
5656
if explainedType.Type == "string" {
5757
TypeRegistryLock.RLock()
58-
instant := TypeRegistry[strings.ToLower(explainedType.TypeString)]
58+
instant = TypeRegistry[strings.ToLower(explainedType.TypeString)]
5959
TypeRegistryLock.RUnlock()
6060
if instant != nil {
6161
regCustomKey(key, instant)
@@ -121,6 +121,17 @@ func RegCustomTypes(registry map[string]source.TypeStruct) {
121121
continue
122122
}
123123
}
124+
// result
125+
if strings.HasPrefix(typeString, "Result<") && strings.HasSuffix(typeString, ">") {
126+
reg := regexp.MustCompile("^Result<(.+)>$")
127+
typeParts := reg.FindStringSubmatch(typeString)
128+
if len(typeParts) > 1 {
129+
r := Result{}
130+
r.SubType = typeParts[1]
131+
regCustomKey(key, &r)
132+
continue
133+
}
134+
}
124135
case "struct":
125136
var names, typeStrings []string
126137
for _, v := range typeStruct.TypeMapping {

types/types_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,10 @@ func TestU256(t *testing.T) {
373373
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes("0x00b5070000000000000000000000000000000000000000000000000000000000")}, nil)
374374
assert.Equal(t, int64(505088), m.ProcessAndUpdateData("U256").(decimal.Decimal).IntPart())
375375
}
376+
377+
func TestXcmV2ResultType(t *testing.T) {
378+
raw := "0204031501020042f2f9dc"
379+
m := ScaleDecoder{}
380+
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes(raw)}, nil)
381+
assert.Equal(t, `{"V2":[{"QueryResponse":{"max_weight":0,"query_id":69,"response":{"ExecutionResult":{"Ok":3707368002}}}}]}`, utiles.ToString(m.ProcessAndUpdateData("VersionedXcm").(map[string]interface{})))
382+
}

0 commit comments

Comments
 (0)