Commit 960e7656 authored by hezhengjun's avatar hezhengjun

add para check for mine

parent 6584e084
......@@ -213,7 +213,7 @@ contract BridgeBank is GoAssetBank, EvmAssetBank {
* @param _amount: value of deposit
*/
function lock(
bytes memory _recipient,
address _recipient,
address _token,
uint256 _amount
)
......
......@@ -34,7 +34,7 @@ contract EvmAssetBank {
*/
event LogLock(
address _from,
bytes _to,
address _to,
address _token,
string _symbol,
uint256 _value,
......@@ -183,7 +183,7 @@ contract EvmAssetBank {
*/
function lockFunds(
address payable _sender,
bytes memory _recipient,
address _recipient,
address _token,
string memory _symbol,
uint256 _amount
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -95,7 +95,6 @@ func (e *evmxgoDB) burn(db dbm.KV, amount int64) ([]*types.KeyValue, []*types.Re
return kvs, logs, nil
}
type evmxgoAction struct {
coinsAccount *account.DB
db dbm.KV
......@@ -115,7 +114,6 @@ func newEvmxgoAction(e *evmxgo, toaddr string, tx *types.Transaction) *evmxgoAct
e.GetBlockTime(), e.GetHeight(), dapp.ExecAddress(string(tx.Execer)), e.GetAPI()}
}
func getManageKey(key string, db dbm.KV) ([]byte, error) {
manageKey := types.ManageKey(key)
value, err := db.Get([]byte(manageKey))
......@@ -183,7 +181,6 @@ func loadEvmxgoMintConfig(db dbm.KV, symbol string) (*evmxgotypes.EvmxgoMintConf
return nil, err // types.ErrBadConfigValue
}
configValue := item.GetArr().Value
if len(configValue) <= 0 {
return nil, evmxgotypes.ErrEvmxgoSymbolNotConfigValue
......@@ -247,21 +244,11 @@ func AddTokenToAssets(addr string, db dbm.KVDB, symbol string) []*types.KeyValue
return kv
}
// 同时比较配置symbol与address参数,和parse返回值是否一致
func check() (address, symbol string, amount int64, err error) {
return "", "", 0, err
}
func parse() (address, symbol string, amount int64, err error) {
// 上一个交易是否lock执行成功,如果是,返回实际参数,不是返回error
return "", "", 0, err
}
// 铸币不可控, 也是麻烦。 2选1
// 1. 谁可以发起
// 2. 是否需要审核 这个会增加管理的成本
// 现在实现选择 1
func (action *evmxgoAction) mint(mint *evmxgotypes.EvmxgoMint) (*types.Receipt, error) {
func (action *evmxgoAction) mint(mint *evmxgotypes.EvmxgoMint, tx2lock *types.Transaction) (*types.Receipt, error) {
if mint == nil {
return nil, types.ErrInvalidParam
}
......@@ -269,7 +256,9 @@ func (action *evmxgoAction) mint(mint *evmxgotypes.EvmxgoMint) (*types.Receipt,
return nil, types.ErrInvalidParam
}
cfg := action.api.GetConfig()
parse()
if err := checkMinePara(mint, tx2lock); nil != err {
return nil, err
}
// TODO check()
evmxgodb, err := loadEvmxgoDB(action.db, mint.GetSymbol())
......@@ -343,4 +332,3 @@ func (action *evmxgoAction) burn(burn *evmxgotypes.EvmxgoBurn) (*types.Receipt,
return &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs}, nil
}
package executor
import (
"errors"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/types"
evmxgotypes "github.com/33cn/plugin/plugin/dapp/evmxgo/types"
......@@ -60,11 +62,18 @@ func (e *evmxgo) Exec_TransferToExec(payload *types.AssetsTransferToExec, tx *ty
}
func (e *evmxgo) Exec_Mint(payload *evmxgotypes.EvmxgoMint, tx *types.Transaction, index int) (*types.Receipt, error) {
action:= newEvmxgoAction(e, "", tx)
return action.mint(payload)
action := newEvmxgoAction(e, "", tx)
txGroup, err := e.GetTxGroup(index)
if nil != err {
return nil, err
}
if len(txGroup) < 2 {
return nil, errors.New("Mint tx should be included in lock tx group")
}
return action.mint(payload, txGroup[0])
}
func (e *evmxgo) Exec_Burn(payload *evmxgotypes.EvmxgoBurn, tx *types.Transaction, index int) (*types.Receipt, error) {
action:= newEvmxgoAction(e, "", tx)
action := newEvmxgoAction(e, "", tx)
return action.burn(payload)
}
package executor
import (
"errors"
"github.com/33cn/chain33/types"
bridgevmxgo "github.com/33cn/plugin/plugin/dapp/bridgevmxgo/contracts/generated"
chain33Abi "github.com/33cn/plugin/plugin/dapp/evm/executor/abi"
evmxgotypes "github.com/33cn/plugin/plugin/dapp/evmxgo/types"
)
const (
LockMethod = "lock"
)
//solidity interface: function lock(address _recipient, address _token, uint256 _amount)
func checkMinePara(mint *evmxgotypes.EvmxgoMint, tx2lock *types.Transaction) error {
unpack, err := chain33Abi.Unpack(tx2lock.Payload, LockMethod, bridgevmxgo.BridgeBankABI)
if err != nil {
return err
}
for _, para := range unpack {
switch para.Name {
case "_recipient":
if mint.Address != para.Value {
return errors.New("Not consitent recipient address")
}
case "_amount":
if mint.Amount != para.Value {
return errors.New("Not consitent Amount")
}
case "_token":
if mint.Token != para.Value {
return errors.New("Not consitent token Address")
}
}
}
return nil
}
......@@ -22,6 +22,7 @@ message EvmxgoMint {
string symbol = 1;
int64 amount = 2;
string address =3;
string token =4;
}
message EvmxgoBurn {
......
This diff is collapsed.
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