Skip to content

Commit

Permalink
use string instead of bytes for creator
Browse files Browse the repository at this point in the history
  • Loading branch information
Son of Odin committed Mar 11, 2024
1 parent 8b8379f commit af404ce
Show file tree
Hide file tree
Showing 66 changed files with 296 additions and 241 deletions.
4 changes: 2 additions & 2 deletions arkeocli/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func runBondProviderCmd(cmd *cobra.Command, args []string) (err error) {
return err
}
msg := types.NewMsgBondProvider(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
bond,
)
Expand Down
2 changes: 1 addition & 1 deletion arkeocli/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func runClaimCmd(cmd *cobra.Command, args []string) (err error) {
}

msg := types.NewMsgClaimContractIncome(
creatorAddr,
creatorAddr.String(),
contract.Id,
nonce,
signature,
Expand Down
2 changes: 1 addition & 1 deletion arkeocli/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func runCloseContractCmd(cmd *cobra.Command, args []string) (err error) {
}

msg := types.NewMsgCloseContract(
clientCtx.GetFromAddress(),
clientCtx.GetFromAddress().String(),
contract.Id,
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions arkeocli/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func runModProviderCmd(cmd *cobra.Command, args []string) (err error) {
status := types.ProviderStatus(types.ProviderStatus_value[strings.ToUpper(argStatus)])

msg := types.NewMsgModProvider(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
argMetaURI,
argMetaNonce,
Expand Down
8 changes: 4 additions & 4 deletions arkeocli/open_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ func runOpenContractCmd(cmd *cobra.Command, args []string) (err error) {
}
deposit := cosmos.NewInt(argDeposit)
msg := types.NewMsgOpenContract(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
common.PubKey(argClientPubkey),
common.PubKey(argDelegatePubkey),
argClientPubkey,
argDelegatePubkey,
contractType,
argDuration,
argSettlementDuration,
Expand Down
22 changes: 11 additions & 11 deletions proto/arkeo/arkeo/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ service Msg {
rpc SetVersion (MsgSetVersion) returns (MsgSetVersionResponse);
}
message MsgBondProvider {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"] ;
string provider = 2 [(gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ] ;
string creator = 1;
string provider = 2;
string service = 3;
string bond = 4 [(cosmos_proto.scalar) = "cosmos.Int" , (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
}

message MsgBondProviderResponse {}

message MsgModProvider {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string provider = 2 [(gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ];
string creator = 1;
string provider = 2;
string service = 3;
string metadata_uri = 4;
uint64 metadata_nonce = 5;
Expand All @@ -46,11 +46,11 @@ message MsgModProvider {
message MsgModProviderResponse {}

message MsgOpenContract {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"] ;
string provider = 2 [(gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ] ;
string creator = 1;
string provider = 2;
string service = 3;
string client = 4 [(gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ] ;
string delegate = 5 [(gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ] ;
string client = 4;
string delegate = 5;
ContractType contract_type = 6;
int64 duration = 7;
cosmos.base.v1beta1.Coin rate = 8 [(gogoproto.nullable) = false ] ;
Expand All @@ -63,14 +63,14 @@ message MsgOpenContract {
message MsgOpenContractResponse {}

message MsgCloseContract {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string creator = 1;
uint64 contract_id = 2;
}

message MsgCloseContractResponse {}

message MsgClaimContractIncome {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string creator = 1;
uint64 contract_id = 2;
bytes signature = 4;
int64 nonce = 5;
Expand All @@ -81,7 +81,7 @@ message MsgClaimContractIncomeResponse {}

// this line is used by starport scaffolding # proto/tx/message
message MsgSetVersion {
string creator = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"] ;
string creator = 1;
int64 version = 2;
}

Expand Down
15 changes: 5 additions & 10 deletions proto/arkeo/claim/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,28 @@ service Msg {
// this line is used by starport scaffolding # proto/tx/rpc
}
message MsgClaimEth {
string creator = 1 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
string creator = 1;
string eth_address = 2; // the adress the claim is for
string signature = 3; // EIP712 signature that has to be signed by ethAddress
}

message MsgClaimEthResponse {}

message MsgClaimArkeo {
string creator = 1 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
string creator = 1;
}

message MsgClaimArkeoResponse {}

message MsgTransferClaim {
string creator = 1 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
string toAddress = 2 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
string creator = 1;
string toAddress = 2;
}

message MsgTransferClaimResponse {}

message MsgAddClaim {
string creator = 1 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
string creator = 1;
Chain chain = 2;
string address = 3;
int64 amount = 4;
Expand Down
2 changes: 1 addition & 1 deletion sentinel/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (aa ArkAuth) Validate(provider common.PubKey) error {
if err != nil {
return fmt.Errorf("internal server error: %w", err)
}
msg := types.NewMsgClaimContractIncome(creator, aa.ContractId, aa.Nonce, aa.Signature)
msg := types.NewMsgClaimContractIncome(creator.String(), aa.ContractId, aa.Nonce, aa.Signature)
err = msg.ValidateBasic()
return err
}
Expand Down
4 changes: 2 additions & 2 deletions x/arkeo/client/cli/tx_bond_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func CmdBondProvider() *cobra.Command {
}

msg := types.NewMsgBondProvider(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
bond,
)
Expand Down
2 changes: 1 addition & 1 deletion x/arkeo/client/cli/tx_claim_contract_income.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func CmdClaimContractIncome() *cobra.Command {
return err
}
msg := types.NewMsgClaimContractIncome(
clientCtx.GetFromAddress(),
clientCtx.GetFromAddress().String(),
argContractId,
argNonce,
signature,
Expand Down
2 changes: 1 addition & 1 deletion x/arkeo/client/cli/tx_close_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CmdCloseContract() *cobra.Command {
}

msg := types.NewMsgCloseContract(
clientCtx.GetFromAddress(),
clientCtx.GetFromAddress().String(),
argContractId,
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/arkeo/client/cli/tx_mod_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func CmdModProvider() *cobra.Command {
}

msg := types.NewMsgModProvider(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
argMetatadataURI,
argMetadataNonce,
Expand Down
8 changes: 4 additions & 4 deletions x/arkeo/client/cli/tx_open_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func CmdOpenContract() *cobra.Command {
}

msg := types.NewMsgOpenContract(
clientCtx.GetFromAddress(),
pubkey,
clientCtx.GetFromAddress().String(),
pubkey.String(),
argService,
cl,
delegate,
cl.String(),
delegate.String(),
types.ContractType(argContractType),
argDuration,
argSettlementDuration,
Expand Down
2 changes: 1 addition & 1 deletion x/arkeo/client/cli/tx_set_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CmdSetVersion() *cobra.Command {
}

msg := types.NewMsgSetVersion(
clientCtx.GetFromAddress(),
clientCtx.GetFromAddress().String(),
argVersion,
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions x/arkeo/keeper/events.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package keeper

import (
"github.com/arkeonetwork/arkeo/common"
"github.com/arkeonetwork/arkeo/common/cosmos"
"github.com/arkeonetwork/arkeo/x/arkeo/types"
)

func (k msgServer) EmitBondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) error {
pk, _ := common.NewPubKey(msg.Provider)
return ctx.EventManager().EmitTypedEvent(
&types.EventBondProvider{
Provider: msg.Provider,
Provider: pk,
Service: msg.Service,
BondRel: msg.Bond,
BondAbs: bond,
Expand All @@ -29,9 +31,10 @@ func (k msgServer) EmitCloseContractEvent(ctx cosmos.Context, contract *types.Co
}

func (k msgServer) EmitModProviderEvent(ctx cosmos.Context, msg *types.MsgModProvider, provider *types.Provider) error {
addr, _ := cosmos.AccAddressFromBech32(msg.Creator)
return ctx.EventManager().EmitTypedEvent(
&types.EventModProvider{
Creator: msg.Creator,
Creator: addr,
Provider: provider.PubKey,
Service: provider.Service.String(),
MetadataUri: provider.MetadataUri,
Expand Down
24 changes: 12 additions & 12 deletions x/arkeo/keeper/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestContractEndBlock(t *testing.T) {
require.NoError(t, err)

modProviderMsg := types.MsgModProvider{
Provider: provider.PubKey,
Provider: provider.PubKey.String(),
Service: common.BTCService.String(),
MinContractDuration: 10,
MaxContractDuration: 500,
Expand All @@ -181,10 +181,10 @@ func TestContractEndBlock(t *testing.T) {
require.NoError(t, k.MintAndSendToAccount(ctx, user1Address, getCoin(common.Tokens(10))))

msg := types.MsgOpenContract{
Provider: providerPubKey,
Provider: providerPubKey.String(),
Service: common.BTCService.String(),
Creator: user1Address,
Client: user1PubKey,
Creator: user1Address.String(),
Client: user1PubKey.String(),
ContractType: types.ContractType_PAY_AS_YOU_GO,
Duration: 100,
Rate: rates[0],
Expand All @@ -195,7 +195,7 @@ func TestContractEndBlock(t *testing.T) {

// have user1 open a contract for a delegate.
delegatePubKey := types.GetRandomPubKey()
msg.Delegate = delegatePubKey
msg.Delegate = delegatePubKey.String()
_, err = s.OpenContract(ctx, &msg)
require.NoError(t, err)

Expand All @@ -205,9 +205,9 @@ func TestContractEndBlock(t *testing.T) {
require.NoError(t, err)

require.NoError(t, k.MintAndSendToAccount(ctx, user2Address, getCoin(common.Tokens(20))))
msg.Delegate = common.EmptyPubKey
msg.Client = user2PubKey
msg.Creator = user2Address
msg.Delegate = common.EmptyPubKey.String()
msg.Client = user2PubKey.String()
msg.Creator = user2Address.String()
_, err = s.OpenContract(ctx, &msg)
require.NoError(t, err)

Expand Down Expand Up @@ -279,7 +279,7 @@ func TestContractEndBlockWithSettlementDuration(t *testing.T) {
require.NoError(t, err)

modProviderMsg := types.MsgModProvider{
Provider: provider.PubKey,
Provider: provider.PubKey.String(),
Service: common.BTCService.String(),
MinContractDuration: 10,
MaxContractDuration: 500,
Expand All @@ -302,10 +302,10 @@ func TestContractEndBlockWithSettlementDuration(t *testing.T) {
require.NoError(t, k.MintAndSendToAccount(ctx, user1Address, getCoin(common.Tokens(10))))

msg := types.MsgOpenContract{
Provider: providerPubKey,
Provider: providerPubKey.String(),
Service: common.BTCService.String(),
Creator: user1Address,
Client: user1PubKey,
Creator: user1Address.String(),
Client: user1PubKey.String(),
ContractType: types.ContractType_PAY_AS_YOU_GO,
Duration: 100,
Rate: rates[0],
Expand Down
5 changes: 3 additions & 2 deletions x/arkeo/keeper/msg_server_bond_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func (k msgServer) BondProviderHandle(ctx cosmos.Context, msg *types.MsgBondProv
if err != nil {
return err
}
provider, err := k.GetProvider(ctx, msg.Provider, service)
pk, _ := common.NewPubKey(msg.Provider)
provider, err := k.GetProvider(ctx, pk, service)
if err != nil {
return err
}
addr, err := msg.Provider.GetMyAddress()
addr, err := pk.GetMyAddress()
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions x/arkeo/keeper/msg_server_bond_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestHandle(t *testing.T) {

// Add to bond
msg := types.MsgBondProvider{
Creator: acct,
Provider: providerPubKey,
Creator: acct.String(),
Provider: providerPubKey.String(),
Service: common.BTCService.String(),
Bond: cosmos.NewInt(common.Tokens(8)),
}
Expand All @@ -33,8 +33,9 @@ func TestHandle(t *testing.T) {
bal := k.GetBalance(ctx, acct)
require.Equal(t, bal.AmountOf(configs.Denom).Int64(), common.Tokens(2))
// check that provider now exists
require.True(t, k.ProviderExists(ctx, msg.Provider, common.BTCService))
provider, err := k.GetProvider(ctx, msg.Provider, common.BTCService)
pk, _ := common.NewPubKey(msg.Provider)
require.True(t, k.ProviderExists(ctx, pk, common.BTCService))
provider, err := k.GetProvider(ctx, pk, common.BTCService)
require.NoError(t, err)
require.Equal(t, provider.Bond.Int64(), common.Tokens(8))

Expand All @@ -48,7 +49,7 @@ func TestHandle(t *testing.T) {
require.Equal(t, bal.AmountOf(configs.Denom).Int64(), common.Tokens(2))

// check provider has same bond
provider, err = k.GetProvider(ctx, msg.Provider, common.BTCService)
provider, err = k.GetProvider(ctx, pk, common.BTCService)
require.NoError(t, err)
require.Equal(t, provider.Bond.Int64(), common.Tokens(8))

Expand All @@ -59,5 +60,5 @@ func TestHandle(t *testing.T) {

bal = k.GetBalance(ctx, acct) // check balance
require.Equal(t, bal.AmountOf(configs.Denom).Int64(), common.Tokens(10))
require.False(t, k.ProviderExists(ctx, msg.Provider, common.BTCService)) // should be removed
require.False(t, k.ProviderExists(ctx, pk, common.BTCService)) // should be removed
}
Loading

0 comments on commit af404ce

Please sign in to comment.