Skip to content

Commit

Permalink
Remove duplicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil committed Mar 15, 2024
1 parent 73f2620 commit d86743a
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions relayer/coreum/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func (c *ContractClient) DeployAndInstantiate(
byteCode []byte,
config InstantiationConfig,
) (sdk.AccAddress, error) {
_, codeID, err := c.deployContract(ctx, sender, byteCode)
_, codeID, err := c.DeployContract(ctx, sender, byteCode)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -583,10 +583,25 @@ func (c *ContractClient) DeployContract(
sender sdk.AccAddress,
byteCode []byte,
) (*sdk.TxResponse, uint64, error) {
txRes, codeID, err := c.deployContract(ctx, sender, byteCode)
msgStoreCode := &wasmtypes.MsgStoreCode{
Sender: sender.String(),
WASMByteCode: byteCode,
}
c.log.Info(ctx, "Deploying contract bytecode.")

txRes, err := client.BroadcastTx(ctx, c.clientCtx.WithFromAddress(sender), c.getTxFactory(), msgStoreCode)
if err != nil {
return nil, 0, errors.Wrap(err, "failed to deploy wasm bytecode")
}
// handle the genereate only case
if txRes == nil {
return nil, 0, nil
}
codeID, err := event.FindUint64EventAttribute(txRes.Events, wasmtypes.EventTypeStoreCode, wasmtypes.AttributeKeyCodeID)
if err != nil {
return nil, 0, err
return nil, 0, errors.Wrap(err, "failed to find code ID in the tx result")
}
c.log.Info(ctx, "The contract bytecode is deployed.", zap.Uint64("codeID", codeID))

return txRes, codeID, nil
}
Expand Down Expand Up @@ -1405,34 +1420,6 @@ func (c *ContractClient) GetProhibitedXRPLAddresses(ctx context.Context) ([]stri
return response.ProhibitedXRPLAddresses, nil
}

func (c *ContractClient) deployContract(
ctx context.Context,
sender sdk.AccAddress,
byteCode []byte,
) (*sdk.TxResponse, uint64, error) {
msgStoreCode := &wasmtypes.MsgStoreCode{
Sender: sender.String(),
WASMByteCode: byteCode,
}
c.log.Info(ctx, "Deploying contract bytecode.")

txRes, err := client.BroadcastTx(ctx, c.clientCtx.WithFromAddress(sender), c.getTxFactory(), msgStoreCode)
if err != nil {
return nil, 0, errors.Wrap(err, "failed to deploy wasm bytecode")
}
// handle the genereate only case
if txRes == nil {
return nil, 0, nil
}
codeID, err := event.FindUint64EventAttribute(txRes.Events, wasmtypes.EventTypeStoreCode, wasmtypes.AttributeKeyCodeID)
if err != nil {
return nil, 0, errors.Wrap(err, "failed to find code ID in the tx result")
}
c.log.Info(ctx, "The contract bytecode is deployed.", zap.Uint64("codeID", codeID))

return txRes, codeID, nil
}

func (c *ContractClient) getPaginatedXRPLTokens(
ctx context.Context,
startAfterKey string,
Expand Down

0 comments on commit d86743a

Please sign in to comment.