Commit cba65734 authored by linj's avatar linj Committed by vipwzw

fix unfreeze create 因为参数中有oneof 不能直接从 json unmarshal的问题, 现在格式 和 pb2json 的格式一致

parent 75165456
...@@ -167,7 +167,7 @@ function init() { ...@@ -167,7 +167,7 @@ function init() {
} }
function CreateRawUnfreezeCreate() { function CreateRawUnfreezeCreate() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[ {"execer" : "unfreeze", "actionName" :"createUnfreeze","payload":{"startTime":10000,"assetExec":"coins","assetSymbol":"bty","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}}]}' req='{"jsonrpc": "2.0", "method" : "unfreeze.CreateRawUnfreezeCreate" , "params":[{"startTime":10000,"assetExec":"coins","assetSymbol":"bty","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}]}'
# echo "#request: $req" # echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp" # echo "#resp: $resp"
......
...@@ -3,3 +3,46 @@ ...@@ -3,3 +3,46 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package types package types
import (
"encoding/json"
"github.com/33cn/chain33/types"
)
type MeansOpt struct {
FixAmount *FixAmount `json:"FixAmount,omitempty"`
LeftProportion *LeftProportion `json:"LeftProportion,omitempty"`
}
type parseUnfreezeCreate struct {
StartTime int64 `protobuf:"varint,1,opt,name=startTime,proto3" json:"startTime,omitempty"`
AssetExec string `protobuf:"bytes,2,opt,name=assetExec,proto3" json:"assetExec,omitempty"`
AssetSymbol string `protobuf:"bytes,3,opt,name=assetSymbol,proto3" json:"assetSymbol,omitempty"`
TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"`
Beneficiary string `protobuf:"bytes,5,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"`
Means string `protobuf:"bytes,6,opt,name=means,proto3" json:"means,omitempty"`
// MeansOpt MeansOpt `json:"MeansOpt,omitempty"`
FixAmount *FixAmount `json:"fixAmount,omitempty"`
LeftProportion *LeftProportion `json:"leftProportion,omitempty"`
}
func (m *UnfreezeCreate) UnmarshalJSON(v []byte) error {
var c parseUnfreezeCreate
err := json.Unmarshal(v, &c)
if err != nil {
return err
}
if c.Means == FixAmountX && c.FixAmount != nil {
m.MeansOpt = &UnfreezeCreate_FixAmount{FixAmount: c.FixAmount}
} else if c.Means == LeftProportionX && c.LeftProportion != nil {
m.MeansOpt = &UnfreezeCreate_LeftProportion{LeftProportion: c.LeftProportion}
} else {
return types.ErrInvalidParam
}
m.StartTime = c.StartTime
m.AssetSymbol, m.AssetExec = c.AssetSymbol, c.AssetExec
m.TotalCount, m.Beneficiary = c.TotalCount, c.Beneficiary
m.Means = c.Means
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment