Skip to content

Commit

Permalink
Generate MarshalJSON for tlb types with SumType
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Oct 25, 2023
1 parent df0ebb3 commit ba90a02
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 124 deletions.
25 changes: 25 additions & 0 deletions abi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ type DedustAsset struct {
} `tlbSumType:"$0010"`
}

func (t *DedustAsset) MarshalJSON() ([]byte, error) {
switch t.SumType {
case "Native":
bytes, err := json.Marshal(t.Native)
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"SumType": "Native","Native":%v}`, string(bytes))), nil
case "Jetton":
bytes, err := json.Marshal(t.Jetton)
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"SumType": "Jetton","Jetton":%v}`, string(bytes))), nil
case "ExtraCurrency":
bytes, err := json.Marshal(t.ExtraCurrency)
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"SumType": "ExtraCurrency","ExtraCurrency":%v}`, string(bytes))), nil
default:
return nil, fmt.Errorf("unknown sum type %v", t.SumType)
}
}

type DedustSwapParams struct {
Deadline uint32
RecipientAddr tlb.MsgAddress
Expand Down
122 changes: 0 additions & 122 deletions liteapi/testdata/config_33651872.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,36 +174,11 @@
"ConfigParam20": {
"GasLimitsPrices": {
"SumType": "GasFlatPfx",
"GasPrices": {
"GasPrice": 0,
"GasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasPricesExt": {
"GasPrice": 0,
"GasLimit": 0,
"SpecialGasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasFlatPfx": {
"FlatGasLimit": 100,
"FlatGasPrice": 1000000,
"Other": {
"SumType": "GasPricesExt",
"GasPrices": {
"GasPrice": 0,
"GasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasPricesExt": {
"GasPrice": 655360000,
"GasLimit": 1000000,
Expand All @@ -212,11 +187,6 @@
"BlockGasLimit": 37000000,
"FreezeDueLimit": 100000000,
"DeleteDueLimit": 1000000000
},
"GasFlatPfx": {
"FlatGasLimit": 0,
"FlatGasPrice": 0,
"Other": null
}
}
}
Expand All @@ -225,36 +195,11 @@
"ConfigParam21": {
"GasLimitsPrices": {
"SumType": "GasFlatPfx",
"GasPrices": {
"GasPrice": 0,
"GasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasPricesExt": {
"GasPrice": 0,
"GasLimit": 0,
"SpecialGasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasFlatPfx": {
"FlatGasLimit": 100,
"FlatGasPrice": 100000,
"Other": {
"SumType": "GasPricesExt",
"GasPrices": {
"GasPrice": 0,
"GasLimit": 0,
"GasCredit": 0,
"BlockGasLimit": 0,
"FreezeDueLimit": 0,
"DeleteDueLimit": 0
},
"GasPricesExt": {
"GasPrice": 65536000,
"GasLimit": 1000000,
Expand All @@ -263,11 +208,6 @@
"BlockGasLimit": 10000000,
"FreezeDueLimit": 100000000,
"DeleteDueLimit": 1000000000
},
"GasFlatPfx": {
"FlatGasLimit": 0,
"FlatGasPrice": 0,
"Other": null
}
}
}
Expand Down Expand Up @@ -344,12 +284,6 @@
"ConfigParam28": {
"CatchainConfig": {
"SumType": "CatchainConfigNew",
"CatchainConfig": {
"McCatchainLifetime": 0,
"ShardCatchainLifetime": 0,
"ShardValidatorsLifetime": 0,
"ShardValidatorsNum": 0
},
"CatchainConfigNew": {
"Flags": 0,
"ShuffleMcValidators": true,
Expand All @@ -363,41 +297,6 @@
"ConfigParam29": {
"ConsensusConfig": {
"SumType": "ConsensusConfigV4",
"ConsensusConfig": {
"RoundCandidates": 0,
"NextCandidateDelayMs": 0,
"ConsensusTimeoutMs": 0,
"FastAttempts": 0,
"AttemptDuration": 0,
"CatchainMaxDeps": 0,
"MaxBlockBytes": 0,
"MaxCollatedBytes": 0
},
"ConsensusConfigNew": {
"Flags": 0,
"NewCatchainIds": false,
"RoundCandidates": 0,
"NextCandidateDelayMs": 0,
"ConsensusTimeoutMs": 0,
"FastAttempts": 0,
"AttemptDuration": 0,
"CatchainMaxDeps": 0,
"MaxBlockBytes": 0,
"MaxCollatedBytes": 0
},
"ConsensusConfigV3": {
"Flags": 0,
"NewCatchainIds": false,
"RoundCandidates": 0,
"NextCandidateDelayMs": 0,
"ConsensusTimeoutMs": 0,
"FastAttempts": 0,
"AttemptDuration": 0,
"CatchainMaxDeps": 0,
"MaxBlockBytes": 0,
"MaxCollatedBytes": 0,
"ProtoVersion": 0
},
"ConsensusConfigV4": {
"Flags": 0,
"NewCatchainIds": true,
Expand Down Expand Up @@ -427,13 +326,6 @@
"ConfigParam32": {
"PrevValidators": {
"SumType": "ValidatorsExt",
"Validators": {
"UtimeSince": 0,
"UtimeUntil": 0,
"Total": 0,
"Main": 0,
"List": {}
},
"ValidatorsExt": {
"UtimeSince": 1698123528,
"UtimeUntil": 1698189064,
Expand Down Expand Up @@ -4229,13 +4121,6 @@
"ConfigParam34": {
"CurValidators": {
"SumType": "ValidatorsExt",
"Validators": {
"UtimeSince": 0,
"UtimeUntil": 0,
"Total": 0,
"Main": 0,
"List": {}
},
"ValidatorsExt": {
"UtimeSince": 1698189064,
"UtimeUntil": 1698254600,
Expand Down Expand Up @@ -8309,13 +8194,6 @@
"ConfigParam79": {
"JettonBridgeParams": {
"SumType": "JettonBridgeParamsV1",
"JettonBridgeParamsV0": {
"BridgeAddress": "0000000000000000000000000000000000000000000000000000000000000000",
"OraclesAddress": "0000000000000000000000000000000000000000000000000000000000000000",
"Oracles": {},
"StateFlags": 0,
"BurnBridgeFee": "0"
},
"JettonBridgeParamsV1": {
"BridgeAddress": "b525eb5b3c5f6e6dcd606bee7ba07a0ec83035212849b7e0559499c0f6bad54d",
"OraclesAddress": "211f1574bf623d14787708c5fdd565e329a25abfa49095e984426f19bcf04974",
Expand Down
Loading

0 comments on commit ba90a02

Please sign in to comment.