Skip to content

Commit

Permalink
add res and fix event emit
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Sep 13, 2023
1 parent b693cd0 commit 6982e15
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 70 deletions.
3 changes: 3 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50587,6 +50587,9 @@ definitions:
type: boolean
fungibleMsgDeployFungibleCoinZRC20Response:
type: object
properties:
address:
type: string
fungibleMsgRemoveForeignCoinResponse:
type: object
fungibleMsgUpdateSystemContractResponse:
Expand Down
4 changes: 3 additions & 1 deletion proto/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ message MsgDeployFungibleCoinZRC20 {
int64 gas_limit = 8;
}

message MsgDeployFungibleCoinZRC20Response {}
message MsgDeployFungibleCoinZRC20Response {
string address = 1;
}

message MsgRemoveForeignCoin {
string creator = 1;
Expand Down
3 changes: 2 additions & 1 deletion testutil/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package sample

import (
"errors"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"hash/fnv"
"math/rand"
"strconv"
"testing"

"github.com/zeta-chain/zetacore/cmd/zetacored/config"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
46 changes: 26 additions & 20 deletions x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"github.com/ethereum/go-ethereum/common"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -31,41 +32,46 @@ import (
// Only the admin policy account is authorized to broadcast this message.
func (k msgServer) DeployFungibleCoinZRC20(goCtx context.Context, msg *types.MsgDeployFungibleCoinZRC20) (*types.MsgDeployFungibleCoinZRC20Response, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

var address common.Address
var err error

if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(zetaObserverTypes.Policy_Type_deploy_fungible_coin) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Deploy can only be executed by the correct policy account")
}
if msg.Decimals > 255 {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "decimals must be less than 256")
}
if msg.CoinType == zetacommon.CoinType_Gas {
_, err := k.SetupChainGasCoinAndPool(ctx, msg.ForeignChainId, msg.Name, msg.Symbol, uint8(msg.Decimals))
address, err = k.SetupChainGasCoinAndPool(ctx, msg.ForeignChainId, msg.Name, msg.Symbol, uint8(msg.Decimals))
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to setupChainGasCoinAndPool")
}
} else {
addr, err := k.DeployZRC20Contract(ctx, msg.Name, msg.Symbol, uint8(msg.Decimals), msg.ForeignChainId, msg.CoinType, msg.ERC20, big.NewInt(msg.GasLimit))
address, err = k.DeployZRC20Contract(ctx, msg.Name, msg.Symbol, uint8(msg.Decimals), msg.ForeignChainId, msg.CoinType, msg.ERC20, big.NewInt(msg.GasLimit))
if err != nil {
return nil, err
}
}

err = ctx.EventManager().EmitTypedEvent(
&types.EventZRC20Deployed{
MsgTypeUrl: sdk.MsgTypeURL(&types.MsgDeployFungibleCoinZRC20{}),
ChainId: msg.ForeignChainId,
Contract: addr.String(),
Name: msg.Name,
Symbol: msg.Symbol,
Decimals: int64(msg.Decimals),
CoinType: msg.CoinType,
Erc20: msg.ERC20,
GasLimit: msg.GasLimit,
},
)
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to emit event")
}

err = ctx.EventManager().EmitTypedEvent(
&types.EventZRC20Deployed{
MsgTypeUrl: sdk.MsgTypeURL(&types.MsgDeployFungibleCoinZRC20{}),
ChainId: msg.ForeignChainId,
Contract: address.String(),
Name: msg.Name,
Symbol: msg.Symbol,
Decimals: int64(msg.Decimals),
CoinType: msg.CoinType,
Erc20: msg.ERC20,
GasLimit: msg.GasLimit,
},
)
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to emit event")
}

return &types.MsgDeployFungibleCoinZRC20Response{}, nil
return &types.MsgDeployFungibleCoinZRC20Response{
Address: address.Hex(),
}, nil
}
147 changes: 99 additions & 48 deletions x/fungible/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6982e15

Please sign in to comment.