Skip to content

Commit aec8bf7

Browse files
committed
SuccessStatus and FailureStatus should not ignore programState and reason
1 parent b587d0f commit aec8bf7

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

client_block.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ func (o GetBlockOption) BuildIgnoreChecker() query.IgnoreChecker {
3232
checkers = append(checkers, query.IgnoreOtherFields(types.Transaction{}, "Id"))
3333
} else {
3434
// Otherwise it will create circular dependencies
35-
checkers = append(checkers, query.IgnoreObjects(types.SuccessStatus{}, types.FailureStatus{}))
35+
checkers = append(checkers, query.IgnoreField(types.SuccessStatus{}, "Block"))
36+
checkers = append(checkers, query.IgnoreField(types.SuccessStatus{}, "Receipts"))
37+
checkers = append(checkers, query.IgnoreField(types.FailureStatus{}, "Block"))
38+
checkers = append(checkers, query.IgnoreField(types.FailureStatus{}, "Receipts"))
3639
}
3740
if !o.WithContractBytecode {
3841
checkers = append(checkers, query.IgnoreField(types.Contract{}, "Bytecode"))

client_block_test.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,15 @@ func Test_GetBlock2(t *testing.T) {
189189
}},
190190
ReceiptsRoot: &types.Bytes32{Hash: common.HexToHash("0x387ae9a320be556f6b79aa5738f59f9381d1919d30b9daacb0da4d412bf7eba3")},
191191
Status: &types.TransactionStatus{
192-
TypeName_: "SuccessStatus",
193-
SuccessStatus: &types.SuccessStatus{},
192+
TypeName_: "SuccessStatus",
193+
SuccessStatus: &types.SuccessStatus{
194+
TransactionId: types.TransactionId{Hash: common.HexToHash("0x9b7a9353faacd4ce91c47707d66c81ec7e4d547905168a592312a94a5c67b69f")},
195+
Time: types.Tai64Timestamp{Time: time.Date(2024, time.April, 15, 2, 44, 2, 0, time.UTC)},
196+
ProgramState: &types.ProgramState{
197+
ReturnType: "RETURN",
198+
Data: types.HexString{Bytes: common.FromHex("0x0000000000000001")},
199+
},
200+
},
194201
},
195202
Receipts: []types.Receipt{{
196203
Pc: util.GetPointer[types.U64](11640),
@@ -273,8 +280,15 @@ func Test_GetBlock2(t *testing.T) {
273280
}},
274281
ReceiptsRoot: &types.Bytes32{Hash: common.HexToHash("0xe7f678a2e8df7da272cf303aff96023da2ab1968b74d86bb92f5b558d38ed6bd")},
275282
Status: &types.TransactionStatus{
276-
TypeName_: "SuccessStatus",
277-
SuccessStatus: &types.SuccessStatus{},
283+
TypeName_: "SuccessStatus",
284+
SuccessStatus: &types.SuccessStatus{
285+
TransactionId: types.TransactionId{Hash: common.HexToHash("0x4928a04ef03e8146c530249c6a2e97e389a3dd3c00deb6efcb652de0ea62da47")},
286+
Time: types.Tai64Timestamp{Time: time.Date(2024, time.April, 15, 2, 44, 2, 0, time.UTC)},
287+
ProgramState: &types.ProgramState{
288+
ReturnType: "RETURN",
289+
Data: types.HexString{Bytes: common.FromHex("0x0000000000000000")},
290+
},
291+
},
278292
},
279293
Receipts: []types.Receipt{{
280294
Pc: util.GetPointer[types.U64](10336),
@@ -316,8 +330,11 @@ func Test_GetBlock2(t *testing.T) {
316330
StateRoot: types.Bytes32{Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")},
317331
},
318332
Status: &types.TransactionStatus{
319-
TypeName_: "SuccessStatus",
320-
SuccessStatus: &types.SuccessStatus{},
333+
TypeName_: "SuccessStatus",
334+
SuccessStatus: &types.SuccessStatus{
335+
TransactionId: types.TransactionId{Hash: common.HexToHash("0x1a978dcf45d87d2793d7da58d45244d68241aa6363d6a435a38c5fdfeafff178")},
336+
Time: types.Tai64Timestamp{Time: time.Date(2024, time.April, 15, 2, 44, 2, 0, time.UTC)},
337+
},
321338
},
322339
RawPayload: types.HexString{Bytes: common.FromHex("0x0000000000000002000000000094e7560000000000000002ae426ee0c79cac25ffe515ca4148e27086669bee7043b23cd380dce443213eff00000000000000002d19f8c34395032b25ae83bf88cd618a8598c6f2459f137c931879b323a41e040000000000000000000000000000000000000000000000000000000000000000000000000094e755000000000000000677777777777777777777777777777777777777777777777777777777777777770000000000000000a24223e950599e9577bd2782388411d5f92c35793dc72fc25355041bb9e2f869000000000000000000000000000000000000000000000000000000000000000000000000000018eb0000000000000000000000000000000000000000000000000000000000000000")},
323340
}},

query/ignore.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import (
77
type IgnoreChecker func(object reflect.Type, field reflect.StructField) bool
88

99
func IgnoreObjects(objs ...any) IgnoreChecker {
10+
objTypeSet := make(map[reflect.Type]bool)
11+
for _, obj := range objs {
12+
objTypeSet[reflect.TypeOf(obj)] = true
13+
}
1014
return func(_ reflect.Type, field reflect.StructField) bool {
1115
fieldType := field.Type
1216
for {
13-
for _, obj := range objs {
14-
if reflect.TypeOf(obj) == fieldType {
15-
return true
16-
}
17+
if objTypeSet[fieldType] {
18+
return true
1719
}
1820
switch fieldType.Kind() {
1921
case reflect.Pointer, reflect.Slice, reflect.Array:
@@ -26,22 +28,20 @@ func IgnoreObjects(objs ...any) IgnoreChecker {
2628
}
2729

2830
func IgnoreField(obj any, fieldName string) IgnoreChecker {
31+
objType := reflect.TypeOf(obj)
2932
return func(object reflect.Type, field reflect.StructField) bool {
30-
return object == reflect.TypeOf(obj) && field.Name == fieldName
33+
return object == objType && field.Name == fieldName
3134
}
3235
}
3336

3437
func IgnoreOtherFields(obj any, fieldNames ...string) IgnoreChecker {
38+
objType := reflect.TypeOf(obj)
39+
fieldNameSet := make(map[string]bool)
40+
for _, fieldName := range fieldNames {
41+
fieldNameSet[fieldName] = true
42+
}
3543
return func(object reflect.Type, field reflect.StructField) bool {
36-
if object != reflect.TypeOf(obj) {
37-
return false
38-
}
39-
for _, fieldName := range fieldNames {
40-
if field.Name == fieldName {
41-
return false
42-
}
43-
}
44-
return true
44+
return object == objType && !fieldNameSet[field.Name]
4545
}
4646
}
4747

0 commit comments

Comments
 (0)