Skip to content

Commit

Permalink
added "chain" parameter across all EVM module commands
Browse files Browse the repository at this point in the history
  • Loading branch information
João Sousa authored and João Sousa committed Jun 2, 2021
1 parent 5955ec8 commit 893e678
Show file tree
Hide file tree
Showing 47 changed files with 1,191 additions and 394 deletions.
58 changes: 27 additions & 31 deletions cmd/axelard/cmd/vald/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func NewMgr(rpc rpc2.Client, broadcaster types2.Broadcaster, sender sdk.AccAddre
}
}

// ProcessDepositConfirmation votes on the correctness of an Ethereum token deposit
// ProcessDepositConfirmation votes on the correctness of an EVM chain token deposit
func (mgr Mgr) ProcessDepositConfirmation(attributes []sdk.Attribute) (err error) {
txID, amount, burnAddr, tokenAddr, confHeight, poll, err := parseDepositConfirmationParams(mgr.cdc, attributes)
chain, txID, amount, burnAddr, tokenAddr, confHeight, poll, err := parseDepositConfirmationParams(mgr.cdc, attributes)
if err != nil {
return sdkerrors.Wrap(err, "Ethereum deposit confirmation failed")
return sdkerrors.Wrap(err, "EVM deposit confirmation failed")
}

confirmed := mgr.validate(txID, confHeight, func(txReceipt *geth.Receipt) bool {
Expand All @@ -65,22 +65,16 @@ func (mgr Mgr) ProcessDepositConfirmation(attributes []sdk.Attribute) (err error
return true
})

msg := &evmTypes.VoteConfirmDepositRequest{
Sender: mgr.sender,
Poll: poll,
TxID: types.Hash(txID),
BurnAddress: types.Address(burnAddr),
Confirmed: confirmed,
}
msg := evmTypes.NewVoteConfirmDepositRequest(mgr.sender, chain, poll, txID, types.Address(burnAddr), confirmed)
mgr.logger.Debug(fmt.Sprintf("broadcasting vote %v for poll %s", msg.Confirmed, poll.String()))
return mgr.broadcaster.Broadcast(msg)
}

// ProcessTokenConfirmation votes on the correctness of an Ethereum token deployment
// ProcessTokenConfirmation votes on the correctness of an EVM chain token deployment
func (mgr Mgr) ProcessTokenConfirmation(attributes []sdk.Attribute) error {
txID, gatewayAddr, tokenAddr, symbol, confHeight, poll, err := parseTokenConfirmationParams(mgr.cdc, attributes)
chain, txID, gatewayAddr, tokenAddr, symbol, confHeight, poll, err := parseTokenConfirmationParams(mgr.cdc, attributes)
if err != nil {
return sdkerrors.Wrap(err, "Ethereum token deployment confirmation failed")
return sdkerrors.Wrap(err, "EVM token deployment confirmation failed")
}

confirmed := mgr.validate(txID, confHeight, func(txReceipt *geth.Receipt) bool {
Expand All @@ -92,35 +86,33 @@ func (mgr Mgr) ProcessTokenConfirmation(attributes []sdk.Attribute) error {
return true
})

msg := &evmTypes.VoteConfirmTokenRequest{
Sender: mgr.sender,
Poll: poll,
TxID: types.Hash(txID),
Confirmed: confirmed,
Symbol: symbol,
}
msg := evmTypes.NewVoteConfirmTokenRequest(mgr.sender, chain, symbol, poll, txID, confirmed)
mgr.logger.Debug(fmt.Sprintf("broadcasting vote %v for poll %s", msg.Confirmed, poll.String()))
return mgr.broadcaster.Broadcast(msg)
}

func parseDepositConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Attribute) (
chain string,
txID common.Hash,
amount sdk.Uint,
burnAddr, tokenAddr common.Address,
confHeight uint64,
poll vote.PollMeta,
err error,
) {
var txIDFound, amountFound, burnAddrFound, tokenAddrFound, confHeightFound, pollFound bool
var chainFound, txIDFound, amountFound, burnAddrFound, tokenAddrFound, confHeightFound, pollFound bool
for _, attribute := range attributes {
switch attribute.Key {
case evmTypes.AttributeKeyChain:
chain = attribute.Value
chainFound = true
case evmTypes.AttributeKeyTxID:
txID = common.HexToHash(attribute.Value)
txIDFound = true
case evmTypes.AttributeKeyAmount:
amount, err = sdk.ParseUint(attribute.Value)
if err != nil {
return [32]byte{}, sdk.Uint{}, [20]byte{}, [20]byte{}, 0, vote.PollMeta{},
return "", common.Hash{}, sdk.Uint{}, common.Address{}, common.Address{}, 0, vote.PollMeta{},
sdkerrors.Wrap(err, "parsing transfer amount failed")
}
amountFound = true
Expand All @@ -133,7 +125,7 @@ func parseDepositConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Att
case evmTypes.AttributeKeyConfHeight:
confHeight, err = strconv.ParseUint(attribute.Value, 10, 64)
if err != nil {
return common.Hash{}, sdk.Uint{}, common.Address{}, common.Address{}, 0, vote.PollMeta{},
return "", common.Hash{}, sdk.Uint{}, common.Address{}, common.Address{}, 0, vote.PollMeta{},
sdkerrors.Wrap(err, "parsing confirmation height failed")
}
confHeightFound = true
Expand All @@ -143,24 +135,28 @@ func parseDepositConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Att
default:
}
}
if !txIDFound || !amountFound || !burnAddrFound || !tokenAddrFound || !confHeightFound || !pollFound {
return common.Hash{}, sdk.Uint{}, common.Address{}, common.Address{}, 0, vote.PollMeta{},
if !chainFound || !txIDFound || !amountFound || !burnAddrFound || !tokenAddrFound || !confHeightFound || !pollFound {
return "", common.Hash{}, sdk.Uint{}, common.Address{}, common.Address{}, 0, vote.PollMeta{},
fmt.Errorf("insufficient event attributes")
}
return txID, amount, burnAddr, tokenAddr, confHeight, poll, nil
return chain, txID, amount, burnAddr, tokenAddr, confHeight, poll, nil
}

func parseTokenConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Attribute) (
chain string,
txID common.Hash,
gatewayAddr, tokenAddr common.Address,
symbol string,
confHeight uint64,
poll vote.PollMeta,
err error,
) {
var txIDFound, gatewayAddrFound, tokenAddrFound, symbolFound, confHeightFound, pollFound bool
var chainFound, txIDFound, gatewayAddrFound, tokenAddrFound, symbolFound, confHeightFound, pollFound bool
for _, attribute := range attributes {
switch attribute.Key {
case evmTypes.AttributeKeyChain:
chain = attribute.Value
chainFound = true
case evmTypes.AttributeKeyTxID:
txID = common.HexToHash(attribute.Value)
txIDFound = true
Expand All @@ -176,7 +172,7 @@ func parseTokenConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Attri
case evmTypes.AttributeKeyConfHeight:
h, err := strconv.Atoi(attribute.Value)
if err != nil {
return common.Hash{}, common.Address{}, common.Address{}, "", 0, vote.PollMeta{},
return "", common.Hash{}, common.Address{}, common.Address{}, "", 0, vote.PollMeta{},
sdkerrors.Wrap(err, "parsing confirmation height failed")
}
confHeight = uint64(h)
Expand All @@ -187,11 +183,11 @@ func parseTokenConfirmationParams(cdc *codec.LegacyAmino, attributes []sdk.Attri
default:
}
}
if !txIDFound || !gatewayAddrFound || !tokenAddrFound || !symbolFound || !confHeightFound || !pollFound {
return common.Hash{}, common.Address{}, common.Address{}, "", 0, vote.PollMeta{},
if !chainFound || !txIDFound || !gatewayAddrFound || !tokenAddrFound || !symbolFound || !confHeightFound || !pollFound {
return "", common.Hash{}, common.Address{}, common.Address{}, "", 0, vote.PollMeta{},
fmt.Errorf("insufficient event attributes")
}
return txID, gatewayAddr, tokenAddr, symbol, confHeight, poll, nil
return chain, txID, gatewayAddr, tokenAddr, symbol, confHeight, poll, nil
}

func (mgr Mgr) validate(txID common.Hash, confHeight uint64, validateLogs func(txReceipt *geth.Receipt) bool) bool {
Expand Down
2 changes: 2 additions & 0 deletions cmd/axelard/cmd/vald/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestMgr_ProccessDepositConfirmation(t *testing.T) {
confHeight := rand.I64Between(0, blockNumber-1)
amount := rand.PosI64() // restrict to int64 so the amount in the receipt doesn't overflow
attributes = []sdk.Attribute{
sdk.NewAttribute(evmTypes.AttributeKeyChain, "Ethereum"),
sdk.NewAttribute(evmTypes.AttributeKeyTxID, common.Bytes2Hex(rand.Bytes(common.HashLength))),
sdk.NewAttribute(evmTypes.AttributeKeyAmount, strconv.FormatUint(uint64(amount), 10)),
sdk.NewAttribute(evmTypes.AttributeKeyBurnAddress, common.Bytes2Hex(burnAddrBytes)),
Expand Down Expand Up @@ -257,6 +258,7 @@ func TestMgr_ProccessTokenConfirmation(t *testing.T) {

symbol := rand.StrBetween(5, 20)
attributes = []sdk.Attribute{
sdk.NewAttribute(evmTypes.AttributeKeyChain, "Ethereum"),
sdk.NewAttribute(evmTypes.AttributeKeyTxID, common.Bytes2Hex(rand.Bytes(common.HashLength))),
sdk.NewAttribute(evmTypes.AttributeKeyGatewayAddress, common.Bytes2Hex(gatewayAddrBytes)),
sdk.NewAttribute(evmTypes.AttributeKeyTokenAddress, common.Bytes2Hex(tokenAddrBytes)),
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Get the signed command data that can be wrapped in an Ethereum transaction to execute the command \[commandID\] on Axelar Gateway

```
axelard query evm command [commandID] [flags]
axelard query evm command [chain] [commandID] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_deploy-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Obtain a raw transaction for the deployment of Axelar Gateway.

```
axelard query evm deploy-gateway [flags]
axelard query evm deploy-gateway [chain] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_gateway-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Query the Axelar Gateway contract address

```
axelard query evm gateway-address [flags]
axelard query evm gateway-address [chain] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_master-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Query an address by key ID

```
axelard query evm master-address [flags]
axelard query evm master-address [chain] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_sendCommand.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Send a transaction signed by \[fromAddress\] that executes the command \[commandID\] to Axelar Gateway

```
axelard query evm sendCommand [commandID] [fromAddress] [flags]
axelard query evm sendCommand [chain] [commandID] [fromAddress] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_sendTx.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Send a transaction that spends tx \[txID\] to chain \[chain\]

```
axelard query evm sendTx [txID] [flags]
axelard query evm sendTx [chain] [txID] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_query_evm_token-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Query a token address by symbol

```
axelard query evm token-address [symbol] [flags]
axelard query evm token-address [chain] [symbol] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_add-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add a new EVM chain

```
axelard tx evm add-chain [name] [native asset] [flags]
axelard tx evm add-chain [chain] [name] [native asset] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_confirm-erc20-deposit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Confirm an ERC20 deposit in an EVM chain transaction that sent given amount of token to a burner address

```
axelard tx evm confirm-erc20-deposit [txID] [amount] [burnerAddr] [flags]
axelard tx evm confirm-erc20-deposit [chain] [txID] [amount] [burnerAddr] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_confirm-erc20-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Confirm an ERC20 token deployment in an EVM chain transaction for a given symbol of token and gateway address

```
axelard tx evm confirm-erc20-token [txID] [symbol] [flags]
axelard tx evm confirm-erc20-token [chain] [txID] [symbol] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_link.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Link a cross chain address to an EVM chain address created by Axelar

```
axelard tx evm link [chain] [address] [symbol] [flags]
axelard tx evm link [chain] [recipient chain] [recipient address] [symbol] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_sign-burn-tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sign burn command for all confirmed token deposits in an EVM chain

```
axelard tx evm sign-burn-tokens [flags]
axelard tx evm sign-burn-tokens [chain] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_sign-deploy-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Signs the call data to deploy a token with the AxelarGateway contract

```
axelard tx evm sign-deploy-token [name] [symbol] [decimals] [capacity] [flags]
axelard tx evm sign-deploy-token [chain] [name] [symbol] [decimals] [capacity] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_sign-pending-transfers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sign all pending transfers to an EVM chain

```
axelard tx evm sign-pending-transfers [flags]
axelard tx evm sign-pending-transfers [chain] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sign a raw EVM chain transaction

```
axelard tx evm sign [tx json file path] [flags]
axelard tx evm sign [chain] [tx json file path] [flags]
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/axelard_tx_evm_transfer-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sign transfer ownership command for an EVM chain contract

```
axelard tx evm transfer-ownership [newOwnerAddr] [flags]
axelard tx evm transfer-ownership [chain] [newOwnerAddr] [flags]
```

### Options
Expand Down
32 changes: 16 additions & 16 deletions docs/cli/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
- [validator-outstanding-rewards \[validator\]](axelard_query_distribution_validator-outstanding-rewards.md) - Query distribution outstanding (un-withdrawn) rewards for a validator and all their delegations
- [evidence](axelard_query_evidence.md) - Query for evidence by hash or for all (paginated) submitted evidence
- [evm](axelard_query_evm.md) - Querying commands for the evm module
- [command \[commandID\]](axelard_query_evm_command.md) - Get the signed command data that can be wrapped in an Ethereum transaction to execute the command \[commandID\] on Axelar Gateway
- [deploy-gateway](axelard_query_evm_deploy-gateway.md) - Obtain a raw transaction for the deployment of Axelar Gateway.
- [gateway-address](axelard_query_evm_gateway-address.md) - Query the Axelar Gateway contract address
- [master-address](axelard_query_evm_master-address.md) - Query an address by key ID
- [sendCommand \[commandID\] \[fromAddress\]](axelard_query_evm_sendCommand.md) - Send a transaction signed by \[fromAddress\] that executes the command \[commandID\] to Axelar Gateway
- [sendTx \[txID\]](axelard_query_evm_sendTx.md) - Send a transaction that spends tx \[txID\] to chain \[chain\]
- [token-address \[symbol\]](axelard_query_evm_token-address.md) - Query a token address by symbol
- [command \[chain\] \[commandID\]](axelard_query_evm_command.md) - Get the signed command data that can be wrapped in an Ethereum transaction to execute the command \[commandID\] on Axelar Gateway
- [deploy-gateway \[chain\]](axelard_query_evm_deploy-gateway.md) - Obtain a raw transaction for the deployment of Axelar Gateway.
- [gateway-address \[chain\]](axelard_query_evm_gateway-address.md) - Query the Axelar Gateway contract address
- [master-address \[chain\]](axelard_query_evm_master-address.md) - Query an address by key ID
- [sendCommand \[chain\] \[commandID\] \[fromAddress\]](axelard_query_evm_sendCommand.md) - Send a transaction signed by \[fromAddress\] that executes the command \[commandID\] to Axelar Gateway
- [sendTx \[chain\] \[txID\]](axelard_query_evm_sendTx.md) - Send a transaction that spends tx \[txID\] to chain \[chain\]
- [token-address \[chain\] \[symbol\]](axelard_query_evm_token-address.md) - Query a token address by symbol
- [gov](axelard_query_gov.md) - Querying commands for the governance module
- [deposit \[proposal-id\] \[depositer-addr\]](axelard_query_gov_deposit.md) - Query details of a deposit
- [deposits \[proposal-id\]](axelard_query_gov_deposits.md) - Query deposits on a proposal
Expand Down Expand Up @@ -130,15 +130,15 @@
- [encode \[file\]](axelard_tx_encode.md) - Encode transactions generated offline
- [evidence](axelard_tx_evidence.md) - Evidence transaction subcommands
- [evm](axelard_tx_evm.md) - evm transactions subcommands
- [add-chain \[name\] \[native asset\]](axelard_tx_evm_add-chain.md) - Add a new EVM chain
- [confirm-erc20-deposit \[txID\] \[amount\] \[burnerAddr\]](axelard_tx_evm_confirm-erc20-deposit.md) - Confirm an ERC20 deposit in an EVM chain transaction that sent given amount of token to a burner address
- [confirm-erc20-token \[txID\] \[symbol\]](axelard_tx_evm_confirm-erc20-token.md) - Confirm an ERC20 token deployment in an EVM chain transaction for a given symbol of token and gateway address
- [link \[chain\] \[address\] \[symbol\]](axelard_tx_evm_link.md) - Link a cross chain address to an EVM chain address created by Axelar
- [sign \[tx json file path\]](axelard_tx_evm_sign.md) - sign a raw EVM chain transaction
- [sign-burn-tokens](axelard_tx_evm_sign-burn-tokens.md) - Sign burn command for all confirmed token deposits in an EVM chain
- [sign-deploy-token \[name\] \[symbol\] \[decimals\] \[capacity\]](axelard_tx_evm_sign-deploy-token.md) - Signs the call data to deploy a token with the AxelarGateway contract
- [sign-pending-transfers](axelard_tx_evm_sign-pending-transfers.md) - Sign all pending transfers to an EVM chain
- [transfer-ownership \[newOwnerAddr\]](axelard_tx_evm_transfer-ownership.md) - Sign transfer ownership command for an EVM chain contract
- [add-chain \[chain\] \[name\] \[native asset\]](axelard_tx_evm_add-chain.md) - Add a new EVM chain
- [confirm-erc20-deposit \[chain\] \[txID\] \[amount\] \[burnerAddr\]](axelard_tx_evm_confirm-erc20-deposit.md) - Confirm an ERC20 deposit in an EVM chain transaction that sent given amount of token to a burner address
- [confirm-erc20-token \[chain\] \[txID\] \[symbol\]](axelard_tx_evm_confirm-erc20-token.md) - Confirm an ERC20 token deployment in an EVM chain transaction for a given symbol of token and gateway address
- [link \[chain\] \[recipient chain\] \[recipient address\] \[symbol\]](axelard_tx_evm_link.md) - Link a cross chain address to an EVM chain address created by Axelar
- [sign \[chain\] \[tx json file path\]](axelard_tx_evm_sign.md) - sign a raw EVM chain transaction
- [sign-burn-tokens \[chain\]](axelard_tx_evm_sign-burn-tokens.md) - Sign burn command for all confirmed token deposits in an EVM chain
- [sign-deploy-token \[chain\] \[name\] \[symbol\] \[decimals\] \[capacity\]](axelard_tx_evm_sign-deploy-token.md) - Signs the call data to deploy a token with the AxelarGateway contract
- [sign-pending-transfers \[chain\]](axelard_tx_evm_sign-pending-transfers.md) - Sign all pending transfers to an EVM chain
- [transfer-ownership \[chain\] \[newOwnerAddr\]](axelard_tx_evm_transfer-ownership.md) - Sign transfer ownership command for an EVM chain contract
- [gov](axelard_tx_gov.md) - Governance transactions subcommands
- [deposit \[proposal-id\] \[deposit\]](axelard_tx_gov_deposit.md) - Deposit tokens for an active proposal
- [submit-proposal](axelard_tx_gov_submit-proposal.md) - Submit a proposal along with an initial deposit
Expand Down
Loading

0 comments on commit 893e678

Please sign in to comment.