diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-20 16:08:40 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:39 +0800 |
commit | 45dee648b6f28f73e781f71a10561dc064327edf (patch) | |
tree | 02bfeeab9f168e782306ab579acedac8e8665de7 | |
parent | bd1f04e40e12c36af4df39450489c477c4f0fb06 (diff) | |
download | go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar.gz go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar.bz2 go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar.lz go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar.xz go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.tar.zst go-tangerine-45dee648b6f28f73e781f71a10561dc064327edf.zip |
dex: use RLP to encode contract payload data
-rw-r--r-- | core/vm/governance.go | 12 | ||||
-rw-r--r-- | dex/governance.go | 12 |
2 files changed, 12 insertions, 12 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go index b2bb531f2..b5d703fd7 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -18,7 +18,6 @@ package vm import ( - "encoding/json" "math/big" "strings" @@ -27,6 +26,7 @@ import ( "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/params" + "github.com/dexon-foundation/dexon/rlp" coreCommon "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core" @@ -1388,7 +1388,7 @@ func (g *GovernanceContract) addDKGComplaint(round *big.Int, comp []byte) ([]byt } var dkgComplaint coreTypes.DKGComplaint - if err := json.Unmarshal(comp, &dkgComplaint); err != nil { + if err := rlp.DecodeBytes(comp, &dkgComplaint); err != nil { g.penalize() return nil, errExecutionReverted } @@ -1427,7 +1427,7 @@ func (g *GovernanceContract) addDKGMasterPublicKey(round *big.Int, mpk []byte) ( } var dkgMasterPK coreTypes.DKGMasterPublicKey - if err := json.Unmarshal(mpk, &dkgMasterPK); err != nil { + if err := rlp.DecodeBytes(mpk, &dkgMasterPK); err != nil { g.penalize() return nil, errExecutionReverted } @@ -1460,7 +1460,7 @@ func (g *GovernanceContract) addDKGFinalize(round *big.Int, finalize []byte) ([] caller := g.contract.Caller() var dkgFinalize coreTypes.DKGFinalize - if err := json.Unmarshal(finalize, &dkgFinalize); err != nil { + if err := rlp.DecodeBytes(finalize, &dkgFinalize); err != nil { g.penalize() return nil, errExecutionReverted } @@ -1556,7 +1556,7 @@ func (g *GovernanceContract) proposeCRS(signedCRS []byte) ([]byte, error) { var dkgMasterPKs []*coreTypes.DKGMasterPublicKey for _, mpk := range g.state.DKGMasterPublicKeys(round) { x := new(coreTypes.DKGMasterPublicKey) - if err := json.Unmarshal(mpk, x); err != nil { + if err := rlp.DecodeBytes(mpk, x); err != nil { panic(err) } dkgMasterPKs = append(dkgMasterPKs, x) @@ -1566,7 +1566,7 @@ func (g *GovernanceContract) proposeCRS(signedCRS []byte) ([]byte, error) { var dkgComplaints []*coreTypes.DKGComplaint for _, comp := range g.state.DKGComplaints(round) { x := new(coreTypes.DKGComplaint) - if err := json.Unmarshal(comp, x); err != nil { + if err := rlp.DecodeBytes(comp, x); err != nil { panic(err) } dkgComplaints = append(dkgComplaints, x) diff --git a/dex/governance.go b/dex/governance.go index 17f7f0751..7e6f2b2f6 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -4,7 +4,6 @@ import ( "context" "crypto/ecdsa" "encoding/hex" - "encoding/json" "math/big" "time" @@ -20,6 +19,7 @@ import ( "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" + "github.com/dexon-foundation/dexon/rlp" "github.com/dexon-foundation/dexon/rpc" ) @@ -200,7 +200,7 @@ func (d *DexconGovernance) NotifyRoundHeight(targetRound, consensusHeight uint64 func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *coreTypes.DKGComplaint) { method := vm.GovernanceContractName2Method["addDKGComplaint"] - encoded, err := json.Marshal(complaint) + encoded, err := rlp.EncodeToBytes(complaint) if err != nil { log.Error("failed to JSON encode complaint to bytes", "err", err) return @@ -225,7 +225,7 @@ func (d *DexconGovernance) DKGComplaints(round uint64) []*coreTypes.DKGComplaint var dkgComplaints []*coreTypes.DKGComplaint for _, pk := range s.DKGComplaints(big.NewInt(int64(round))) { x := new(coreTypes.DKGComplaint) - if err := json.Unmarshal(pk, x); err != nil { + if err := rlp.DecodeBytes(pk, x); err != nil { panic(err) } dkgComplaints = append(dkgComplaints, x) @@ -237,7 +237,7 @@ func (d *DexconGovernance) DKGComplaints(round uint64) []*coreTypes.DKGComplaint func (d *DexconGovernance) AddDKGMasterPublicKey(round uint64, masterPublicKey *coreTypes.DKGMasterPublicKey) { method := vm.GovernanceContractName2Method["addDKGMasterPublicKey"] - encoded, err := json.Marshal(masterPublicKey) + encoded, err := rlp.EncodeToBytes(masterPublicKey) if err != nil { log.Error("failed to JSON encode mpk to bytes", "err", err) return @@ -262,7 +262,7 @@ func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*coreTypes.DKGMas var dkgMasterPKs []*coreTypes.DKGMasterPublicKey for _, pk := range s.DKGMasterPublicKeys(big.NewInt(int64(round))) { x := new(coreTypes.DKGMasterPublicKey) - if err := json.Unmarshal(pk, x); err != nil { + if err := rlp.DecodeBytes(pk, x); err != nil { panic(err) } dkgMasterPKs = append(dkgMasterPKs, x) @@ -274,7 +274,7 @@ func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*coreTypes.DKGMas func (d *DexconGovernance) AddDKGFinalize(round uint64, final *coreTypes.DKGFinalize) { method := vm.GovernanceContractName2Method["addDKGFinalize"] - encoded, err := json.Marshal(final) + encoded, err := rlp.EncodeToBytes(final) if err != nil { log.Error("failed to JSON encode finalize to bytes", "err", err) return |