-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporary command to upload smart contracts (#265)
- Loading branch information
Showing
20 changed files
with
957 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/palomachain/paloma/x/evm/types" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdUploadNewSmartContractTemp() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "upload-new-smart-contract-temp [abi] [bytecode] [constructor-input] [chain-id]", | ||
Short: "Broadcast message UploadNewSmartContractTemp", | ||
Args: cobra.ExactArgs(4), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argAbi := args[0] | ||
argBytecode := args[1] | ||
argConstructorInput := args[2] | ||
argChainID := args[3] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgUploadNewSmartContractTemp( | ||
clientCtx.GetFromAddress().String(), | ||
argAbi, | ||
argBytecode, | ||
argConstructorInput, | ||
argChainID, | ||
|
||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/palomachain/paloma/x/evm/types" | ||
) | ||
|
||
func (k msgServer) UploadNewSmartContractTemp(goCtx context.Context, msg *types.MsgUploadNewSmartContractTemp) (*types.MsgUploadNewSmartContractTempResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
err := k.addUploadSmartContractToConsensus(ctx, msg.GetChainID(), &types.UploadSmartContract{ | ||
Bytecode: common.FromHex(msg.GetBytecode()), | ||
Abi: []byte(msg.GetAbi()), | ||
ConstructorInput: common.FromHex(msg.GetConstructorInput()), | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgUploadNewSmartContractTempResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgUploadNewSmartContractTemp = "upload_new_smart_contract_temp" | ||
|
||
var _ sdk.Msg = &MsgUploadNewSmartContractTemp{} | ||
|
||
func NewMsgUploadNewSmartContractTemp(creator string, abi string, bytecode string, constructorInput string, chainID string) *MsgUploadNewSmartContractTemp { | ||
return &MsgUploadNewSmartContractTemp{ | ||
Creator: creator, | ||
Abi: abi, | ||
Bytecode: bytecode, | ||
ConstructorInput: constructorInput, | ||
ChainID: chainID, | ||
} | ||
} | ||
|
||
func (msg *MsgUploadNewSmartContractTemp) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgUploadNewSmartContractTemp) Type() string { | ||
return TypeMsgUploadNewSmartContractTemp | ||
} | ||
|
||
func (msg *MsgUploadNewSmartContractTemp) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgUploadNewSmartContractTemp) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgUploadNewSmartContractTemp) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) | ||
} | ||
return nil | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
x/evm/types/message_upload_new_smart_contract_temp_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/stretchr/testify/require" | ||
"github.com/palomachain/paloma/testutil/sample" | ||
) | ||
|
||
func TestMsgUploadNewSmartContractTemp_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg MsgUploadNewSmartContractTemp | ||
err error | ||
}{ | ||
{ | ||
name: "invalid address", | ||
msg: MsgUploadNewSmartContractTemp{ | ||
Creator: "invalid_address", | ||
}, | ||
err: sdkerrors.ErrInvalidAddress, | ||
}, { | ||
name: "valid address", | ||
msg: MsgUploadNewSmartContractTemp{ | ||
Creator: sample.AccAddress(), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.msg.ValidateBasic() | ||
if tt.err != nil { | ||
require.ErrorIs(t, err, tt.err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
Oops, something went wrong.