Skip to content

Commit

Permalink
Merge pull request #1428 from ahmedrns/1119
Browse files Browse the repository at this point in the history
Create user account without user name
  • Loading branch information
MikeSofaer committed Nov 24, 2022
2 parents c619dbf + 3bc7733 commit b5a3f0c
Show file tree
Hide file tree
Showing 32 changed files with 982 additions and 312 deletions.
6 changes: 3 additions & 3 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: a6f9d5a44af94a75bf434d95934e79c2
commit: 5965e4f2bf8747b4b076ccaa8e11f464
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 6652e3443c3b4504bb3bf82e73a7e409
commit: 34d970b699f84aa382f3c29773a60836
- remote: buf.build
owner: googleapis
repository: googleapis
commit: e9fcfb66f77242e5b8fd4564d7a01033
commit: 5abafbf55b5c4c07ad5fb06d2599560f
6 changes: 4 additions & 2 deletions proto/pylons/pylons/item.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ message ItemHistory {
string cookbook_id = 2;
string id = 3;
string from = 4;
string to = 5;
int64 created_at = 6;
string fromAddress = 5;
string to = 6;
string toAddress = 7;
int64 created_at = 8;
}
15 changes: 11 additions & 4 deletions proto/pylons/pylons/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ option go_package = "github.com/Pylons-tech/pylons/x/pylons/types";

// Msg defines the Msg service.
service Msg {
rpc AppleIap(MsgAppleIap) returns (MsgAppleIapResponse);
rpc AppleIap(MsgAppleIap) returns (MsgAppleIapResponse);
rpc AddStripeRefund(MsgAddStripeRefund) returns (MsgAddStripeRefundResponse);
// this line is used by starport scaffolding # proto/tx/rpc
// //this line is used by starport scaffolding # proto/tx/rpc
rpc BurnDebtToken(MsgBurnDebtToken) returns (MsgBurnDebtTokenResponse);
rpc UpdateAccount(MsgUpdateAccount) returns (MsgUpdateAccountResponse);
rpc FulfillTrade(MsgFulfillTrade) returns (MsgFulfillTradeResponse);
Expand All @@ -28,6 +28,7 @@ service Msg {
rpc TransferCookbook(MsgTransferCookbook) returns (MsgTransferCookbookResponse);
rpc GoogleInAppPurchaseGetCoins(MsgGoogleInAppPurchaseGetCoins) returns (MsgGoogleInAppPurchaseGetCoinsResponse);
rpc CreateAccount(MsgCreateAccount) returns (MsgCreateAccountResponse);
rpc SetUsername(MsgSetUsername) returns (MsgSetUsernameResponse);
rpc SendItems(MsgSendItems) returns (MsgSendItemsResponse);
rpc ExecuteRecipe(MsgExecuteRecipe) returns (MsgExecuteRecipeResponse);
rpc SetItemString(MsgSetItemString) returns (MsgSetItemStringResponse);
Expand Down Expand Up @@ -75,10 +76,16 @@ message MsgUpdateAccountResponse {
}

message MsgCreateAccount {
string creator = 1;
string token = 2;
string referral_address = 3;
}

message MsgSetUsername {
string creator = 1;
string username = 2;
string token = 3;
string referral_address = 4;
}
message MsgSetUsernameResponse {
}

message MsgCreateAccountResponse {
Expand Down
3 changes: 1 addition & 2 deletions testutil/cli/cli_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ func GenerateAddressWithAccount(ctx client.Context, t *testing.T, net *network.N
accs := GenerateAddressesInKeyring(ctx.Keyring, 1)
common := CommonArgs(accs[0].String(), net)

username := "user"
usernameToken := "usernameToken"
types.UpdateAppCheckFlagTest(types.FlagTrue)

// create account
args := []string{username, usernameToken, ""}
args := []string{usernameToken, ""}
args = append(args, common...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateAccount(), args)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ func New(t *testing.T, configs ...network.Config) *network.Network {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()),
}

args := []string{fmt.Sprintf("val%d", i), "testtoken", ""}
args := []string{"testtoken", ""}
args = append(args, flags...)
args1 := []string{fmt.Sprintf("val%v", i)}
args1 = append(args1, flags...)
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateAccount(), args)
require.NoError(t, err)
_, err = clitestutil.ExecTestCLICmd(ctx, cli.CmdSetUsername(), args1)
require.NoError(t, err)
// var resp sdk.TxResponse
// require.NoError(t, ctx.JSONCodec.UnmarshalJSON(out.Bytes(), &resp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,10 @@ class ItemHistory extends $pb.GeneratedMessage {
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'cookbookId')
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'from')
..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'to')
..aInt64(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'createdAt')
..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'fromAddress')
..aOS(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'to')
..aOS(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'toAddress')
..aInt64(8, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'createdAt')
..hasRequiredFields = false
;

Expand All @@ -423,7 +425,9 @@ class ItemHistory extends $pb.GeneratedMessage {
$core.String? cookbookId,
$core.String? id,
$core.String? from,
$core.String? fromAddress,
$core.String? to,
$core.String? toAddress,
$fixnum.Int64? createdAt,
}) {
final _result = create();
Expand All @@ -436,9 +440,15 @@ class ItemHistory extends $pb.GeneratedMessage {
if (from != null) {
_result.from = from;
}
if (fromAddress != null) {
_result.fromAddress = fromAddress;
}
if (to != null) {
_result.to = to;
}
if (toAddress != null) {
_result.toAddress = toAddress;
}
if (createdAt != null) {
_result.createdAt = createdAt;
}
Expand Down Expand Up @@ -493,20 +503,38 @@ class ItemHistory extends $pb.GeneratedMessage {
void clearFrom() => clearField(4);

@$pb.TagNumber(5)
$core.String get to => $_getSZ(3);
$core.String get fromAddress => $_getSZ(3);
@$pb.TagNumber(5)
set to($core.String v) { $_setString(3, v); }
set fromAddress($core.String v) { $_setString(3, v); }
@$pb.TagNumber(5)
$core.bool hasTo() => $_has(3);
$core.bool hasFromAddress() => $_has(3);
@$pb.TagNumber(5)
void clearTo() => clearField(5);
void clearFromAddress() => clearField(5);

@$pb.TagNumber(6)
$fixnum.Int64 get createdAt => $_getI64(4);
$core.String get to => $_getSZ(4);
@$pb.TagNumber(6)
set createdAt($fixnum.Int64 v) { $_setInt64(4, v); }
set to($core.String v) { $_setString(4, v); }
@$pb.TagNumber(6)
$core.bool hasCreatedAt() => $_has(4);
$core.bool hasTo() => $_has(4);
@$pb.TagNumber(6)
void clearCreatedAt() => clearField(6);
void clearTo() => clearField(6);

@$pb.TagNumber(7)
$core.String get toAddress => $_getSZ(5);
@$pb.TagNumber(7)
set toAddress($core.String v) { $_setString(5, v); }
@$pb.TagNumber(7)
$core.bool hasToAddress() => $_has(5);
@$pb.TagNumber(7)
void clearToAddress() => clearField(7);

@$pb.TagNumber(8)
$fixnum.Int64 get createdAt => $_getI64(6);
@$pb.TagNumber(8)
set createdAt($fixnum.Int64 v) { $_setInt64(6, v); }
@$pb.TagNumber(8)
$core.bool hasCreatedAt() => $_has(6);
@$pb.TagNumber(8)
void clearCreatedAt() => clearField(8);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ const ItemHistory$json = const {
const {'1': 'cookbook_id', '3': 2, '4': 1, '5': 9, '10': 'cookbookId'},
const {'1': 'id', '3': 3, '4': 1, '5': 9, '10': 'id'},
const {'1': 'from', '3': 4, '4': 1, '5': 9, '10': 'from'},
const {'1': 'to', '3': 5, '4': 1, '5': 9, '10': 'to'},
const {'1': 'created_at', '3': 6, '4': 1, '5': 3, '10': 'createdAt'},
const {'1': 'from_address', '3': 5, '4': 1, '5': 9, '10': 'fromAddress'},
const {'1': 'to', '3': 6, '4': 1, '5': 9, '10': 'to'},
const {'1': 'to_address', '3': 7, '4': 1, '5': 9, '10': 'toAddress'},
const {'1': 'created_at', '3': 8, '4': 1, '5': 3, '10': 'createdAt'},
],
};

/// Descriptor for `ItemHistory`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List itemHistoryDescriptor = $convert.base64Decode('CgtJdGVtSGlzdG9yeRIfCgtjb29rYm9va19pZBgCIAEoCVIKY29va2Jvb2tJZBIOCgJpZBgDIAEoCVICaWQSEgoEZnJvbRgEIAEoCVIEZnJvbRIOCgJ0bxgFIAEoCVICdG8SHQoKY3JlYXRlZF9hdBgGIAEoA1IJY3JlYXRlZEF0');
final $typed_data.Uint8List itemHistoryDescriptor = $convert.base64Decode('CgtJdGVtSGlzdG9yeRIfCgtjb29rYm9va19pZBgCIAEoCVIKY29va2Jvb2tJZBIOCgJpZBgDIAEoCVICaWQSEgoEZnJvbRgEIAEoCVIEZnJvbRIhCgxmcm9tX2FkZHJlc3MYBSABKAlSC2Zyb21BZGRyZXNzEg4KAnRvGAYgASgJUgJ0bxIdCgp0b19hZGRyZXNzGAcgASgJUgl0b0FkZHJlc3MSHQoKY3JlYXRlZF9hdBgIIAEoA1IJY3JlYXRlZEF0');
9 changes: 3 additions & 6 deletions x/pylons/client/cli/query_list_referrals_by_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ func settingPylonsAccount(ctx client.Context, t *testing.T, net *network.Network
acc := util.GenerateAddressesInKeyring(ctx.Keyring, 2)
common := util.CommonArgs(acc[0].String(), net)

usernameReferral := "testReferralUsername"
usernameTokenReferral := "testUsernameToken"
types.UpdateAppCheckFlagTest(types.FlagTrue)

args := []string{}
args = append(args, usernameReferral, usernameTokenReferral, "")
args = append(args, usernameTokenReferral, "")
args = append(args, common...)

_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateAccount(), args)
Expand All @@ -35,7 +34,7 @@ func settingPylonsAccount(ctx client.Context, t *testing.T, net *network.Network
common = util.CommonArgs(acc[1].String(), net)

args = []string{}
args = append(args, username, usernameToken, referralAddress)
args = append(args, usernameToken, referralAddress)
args = append(args, common...)

_, err = clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateAccount(), args)
Expand All @@ -55,7 +54,7 @@ func TestCmdListReferralsByAddress(t *testing.T) {
net := network.New(t)
ctx := net.Validators[0].ClientCtx

address, username, referral := settingPylonsAccount(ctx, t, net)
address, _, referral := settingPylonsAccount(ctx, t, net)

for _, tc := range []struct {
desc string
Expand All @@ -67,14 +66,12 @@ func TestCmdListReferralsByAddress(t *testing.T) {
{
desc: "Valid",
address: address,
username: username,
referral: referral,
shouldErr: false,
},
{
desc: "Invalid - referral address",
address: address,
username: username,
referral: "Invalid",
shouldErr: true,
},
Expand Down
2 changes: 0 additions & 2 deletions x/pylons/client/cli/query_list_trades_by_creator_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli_test

import (
"strconv"
"testing"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -23,7 +22,6 @@ func createAccountInKeyring(ctx client.Context, t *testing.T, net *network.Netwo
for i := 0; i < n; i++ {
common := util.CommonArgs(acc[0].String(), net)
args := []string{}
args = append(args, "testUsername"+strconv.Itoa(i))
args = append(args, "")
args = append(args, "")
args = append(args, common...)
Expand Down
1 change: 1 addition & 0 deletions x/pylons/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdGoogleInAppPurchaseGetCoins())

cmd.AddCommand(CmdCreateAccount())
cmd.AddCommand(CmdSetUsername())

cmd.AddCommand(CmdSendItems())

Expand Down
59 changes: 47 additions & 12 deletions x/pylons/client/cli/tx_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,81 @@ var _ = strconv.Itoa(0)

func CmdCreateAccount() *cobra.Command {
cmd := &cobra.Command{
Use: "create-account [username] [token] [referralAddress]",
Use: "create-account [token] [referralAddress]",
Short: "initialize account from address",
Long: `
Create a new account using an existing key from the keyring.
`,
Example: `
pylonsd tx pylons create-account app-check-token pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkei --from joe
or
pylonsd tx pylons create-account app-check-token pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkel --from pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkee
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
token := args[0]
referral := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgCreateAccount(clientCtx.GetFromAddress().String(), token, referral)
if err := msg.ValidateBasic(); err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags())
return GenerateOrBroadcastMsgs(clientCtx, txf, []sdk.Msg{msg}...)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func CmdSetUsername() *cobra.Command {
cmd := &cobra.Command{
Use: "set-username [username]",
Short: "set username of account from address",
Long: `
Set username of an account using an existing key from the keyring.
A valid username must respect the following rules:
- Contain alphanumeric characters (a-z, A-Z, 0-9)
- Contain non-repeating underscore (_), hyphen (-), and space characters
- Cannot begin or end with (_), hyphen (-), or space
- Cannot be an existing valid Cosmos SDK address
Note that the username and the key name that are used to sign the transaction _are not the same_.
Note that the username and the key name that are used to sign the transaction _are not the same_.
`,
Example: `
pylonsd tx pylons create-account john app-check-token pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkei --from joe
pylonsd tx pylons set-username myusername --from joe
or
pylonsd tx pylons create-account john app-check-token pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkel --from pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkee
pylonsd tx pylons set-username myusername --from pylo1tqqp6wmctv0ykatyaefsqy6stj92lnt800lkee
`,
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
username := args[0]
token := args[1]
referral := args[2]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgCreateAccount(clientCtx.GetFromAddress().String(), username, token, referral)
msg := types.NewMsgSetUsername(clientCtx.GetFromAddress().String(), username)
if err := msg.ValidateBasic(); err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags())
return GenerateOrBroadcastMsgs(clientCtx, txf, []sdk.Msg{msg}...)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

Expand Down
3 changes: 0 additions & 3 deletions x/pylons/client/cli/tx_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func TestCmdCreateAccount(t *testing.T) {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
args := []string{}
args = append(args, tc.username)
args = append(args, tc.token)
args = append(args, tc.referralAddress)
args = append(args, tc.common...)
Expand Down Expand Up @@ -144,13 +143,11 @@ func TestCmdUpdateAccount(t *testing.T) {

fundToken(t, net, []string{acc[0].String(), acc[1].String()})

username := "testUsername"
token := ""
referralAddress := ""
common := util.CommonArgs(acc[0].String(), net)

args := []string{}
args = append(args, username)
args = append(args, token)
args = append(args, referralAddress)
args = append(args, common...)
Expand Down
1 change: 1 addition & 0 deletions x/pylons/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
username := types.Username{Value: elem.Username}
accountAddr := types.AccountAddr{Value: elem.AccountAddr}
k.SetPylonsAccount(ctx, accountAddr, username)
k.UpdatePylonsAccount(ctx, accountAddr, username)
}

// Set all the trade
Expand Down
Loading

0 comments on commit b5a3f0c

Please sign in to comment.