Skip to content

Commit 3f87822

Browse files
committed
Merge branch 'custom/0.45.3/vesting-acc' into custom/0.45.3/v2.0.x-sdk-0.45.3
* custom/0.45.3/vesting-acc: feat: periodic vesting msg, cherry-pick 147d798 cosmos#9596
2 parents 1843288 + 82c4293 commit 3f87822

File tree

7 files changed

+853
-91
lines changed

7 files changed

+853
-91
lines changed

docs/core/proto-docs.md

+94-62
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,6 @@
579579

580580
- [Query](#cosmos.upgrade.v1beta1.Query)
581581

582-
- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
583-
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
584-
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)
585-
586-
- [Msg](#cosmos.vesting.v1beta1.Msg)
587-
588582
- [cosmos/vesting/v1beta1/vesting.proto](#cosmos/vesting/v1beta1/vesting.proto)
589583
- [BaseVestingAccount](#cosmos.vesting.v1beta1.BaseVestingAccount)
590584
- [ContinuousVestingAccount](#cosmos.vesting.v1beta1.ContinuousVestingAccount)
@@ -593,6 +587,14 @@
593587
- [PeriodicVestingAccount](#cosmos.vesting.v1beta1.PeriodicVestingAccount)
594588
- [PermanentLockedAccount](#cosmos.vesting.v1beta1.PermanentLockedAccount)
595589

590+
- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
591+
- [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount)
592+
- [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse)
593+
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
594+
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)
595+
596+
- [Msg](#cosmos.vesting.v1beta1.Msg)
597+
596598
- [Scalar Value Types](#scalar-value-types)
597599

598600

@@ -8282,62 +8284,6 @@ Since: cosmos-sdk 0.43 | GET|/cosmos/upgrade/v1beta1/module_versions|
82828284

82838285

82848286

8285-
<a name="cosmos/vesting/v1beta1/tx.proto"></a>
8286-
<p align="right"><a href="#top">Top</a></p>
8287-
8288-
## cosmos/vesting/v1beta1/tx.proto
8289-
8290-
8291-
8292-
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>
8293-
8294-
### MsgCreateVestingAccount
8295-
MsgCreateVestingAccount defines a message that enables creating a vesting
8296-
account.
8297-
8298-
8299-
| Field | Type | Label | Description |
8300-
| ----- | ---- | ----- | ----------- |
8301-
| `from_address` | [string](#string) | | |
8302-
| `to_address` | [string](#string) | | |
8303-
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
8304-
| `end_time` | [int64](#int64) | | |
8305-
| `delayed` | [bool](#bool) | | |
8306-
8307-
8308-
8309-
8310-
8311-
8312-
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>
8313-
8314-
### MsgCreateVestingAccountResponse
8315-
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
8316-
8317-
8318-
8319-
8320-
8321-
<!-- end messages -->
8322-
8323-
<!-- end enums -->
8324-
8325-
<!-- end HasExtensions -->
8326-
8327-
8328-
<a name="cosmos.vesting.v1beta1.Msg"></a>
8329-
8330-
### Msg
8331-
Msg defines the bank Msg service.
8332-
8333-
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
8334-
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
8335-
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |
8336-
8337-
<!-- end services -->
8338-
8339-
8340-
83418287
<a name="cosmos/vesting/v1beta1/vesting.proto"></a>
83428288
<p align="right"><a href="#top">Top</a></p>
83438289

@@ -8461,6 +8407,92 @@ Since: cosmos-sdk 0.43
84618407

84628408

84638409

8410+
<a name="cosmos/vesting/v1beta1/tx.proto"></a>
8411+
<p align="right"><a href="#top">Top</a></p>
8412+
8413+
## cosmos/vesting/v1beta1/tx.proto
8414+
8415+
8416+
8417+
<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount"></a>
8418+
8419+
### MsgCreatePeriodicVestingAccount
8420+
MsgCreatePeriodicVestingAccount defines a message that enables creating a periodic vesting
8421+
account.
8422+
8423+
8424+
| Field | Type | Label | Description |
8425+
| ----- | ---- | ----- | ----------- |
8426+
| `from_address` | [string](#string) | | |
8427+
| `to_address` | [string](#string) | | |
8428+
| `start_time` | [int64](#int64) | | |
8429+
| `vesting_periods` | [Period](#cosmos.vesting.v1beta1.Period) | repeated | |
8430+
8431+
8432+
8433+
8434+
8435+
8436+
<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse"></a>
8437+
8438+
### MsgCreatePeriodicVestingAccountResponse
8439+
MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type.
8440+
8441+
8442+
8443+
8444+
8445+
8446+
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>
8447+
8448+
### MsgCreateVestingAccount
8449+
MsgCreateVestingAccount defines a message that enables creating a vesting
8450+
account.
8451+
8452+
8453+
| Field | Type | Label | Description |
8454+
| ----- | ---- | ----- | ----------- |
8455+
| `from_address` | [string](#string) | | |
8456+
| `to_address` | [string](#string) | | |
8457+
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
8458+
| `end_time` | [int64](#int64) | | |
8459+
| `delayed` | [bool](#bool) | | |
8460+
8461+
8462+
8463+
8464+
8465+
8466+
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>
8467+
8468+
### MsgCreateVestingAccountResponse
8469+
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
8470+
8471+
8472+
8473+
8474+
8475+
<!-- end messages -->
8476+
8477+
<!-- end enums -->
8478+
8479+
<!-- end HasExtensions -->
8480+
8481+
8482+
<a name="cosmos.vesting.v1beta1.Msg"></a>
8483+
8484+
### Msg
8485+
Msg defines the bank Msg service.
8486+
8487+
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
8488+
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
8489+
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |
8490+
| `CreatePeriodicVestingAccount` | [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount) | [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse) | CreatePeriodicVestingAccount defines a method that enables creating a periodic vesting account. | |
8491+
8492+
<!-- end services -->
8493+
8494+
8495+
84648496
## Scalar Value Types
84658497

84668498
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |

proto/cosmos/vesting/v1beta1/tx.proto

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cosmos.vesting.v1beta1;
33

44
import "gogoproto/gogo.proto";
55
import "cosmos/base/v1beta1/coin.proto";
6+
import "cosmos/vesting/v1beta1/vesting.proto";
67

78
option go_package = "github.com/cosmos/cosmos-sdk/x/auth/vesting/types";
89

@@ -11,6 +12,9 @@ service Msg {
1112
// CreateVestingAccount defines a method that enables creating a vesting
1213
// account.
1314
rpc CreateVestingAccount(MsgCreateVestingAccount) returns (MsgCreateVestingAccountResponse);
15+
// CreatePeriodicVestingAccount defines a method that enables creating a
16+
// periodic vesting account.
17+
rpc CreatePeriodicVestingAccount(MsgCreatePeriodicVestingAccount) returns (MsgCreatePeriodicVestingAccountResponse);
1418
}
1519

1620
// MsgCreateVestingAccount defines a message that enables creating a vesting
@@ -28,4 +32,18 @@ message MsgCreateVestingAccount {
2832
}
2933

3034
// MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
31-
message MsgCreateVestingAccountResponse {}
35+
message MsgCreateVestingAccountResponse {}
36+
37+
// MsgCreatePeriodicVestingAccount defines a message that enables creating a periodic vesting
38+
// account.
39+
message MsgCreatePeriodicVestingAccount {
40+
option (gogoproto.equal) = false;
41+
42+
string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""];
43+
string to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""];
44+
int64 start_time = 3 [(gogoproto.moretags) = "yaml:\"start_time\""];
45+
repeated Period vesting_periods = 4 [(gogoproto.nullable) = false];
46+
}
47+
48+
// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type.
49+
message MsgCreatePeriodicVestingAccountResponse {}

x/auth/spec/07_client.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ simd tx vesting --help
394394

395395
#### create-periodic-vesting-account
396396

397-
The `create-periodic-vesting-account` command creates a new vesting account funded with an allocation of tokens, where a sequence of coins and period length in seconds. Periods are sequential, in that the duration of of a period only starts at the end of the previous period. The duration of the first period starts upon account creation.
397+
The `create-periodic-vesting-account` command creates a new vesting account funded with an allocation of tokens, where a sequence of coins and period length in seconds. Periods are sequential, in that the duration of a period only starts at the end of the previous period. The duration of the first period starts upon account creation.
398398

399399
```bash
400400
simd tx vesting create-periodic-vesting-account [to_address] [periods_json_file] [flags]

x/auth/vesting/client/cli/tx.go

+93
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package cli
22

33
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
47
"strconv"
58

69
"github.com/spf13/cobra"
@@ -29,6 +32,7 @@ func GetTxCmd() *cobra.Command {
2932

3033
txCmd.AddCommand(
3134
NewMsgCreateVestingAccountCmd(),
35+
NewMsgCreatePeriodicVestingAccountCmd(),
3236
)
3337

3438
return txCmd
@@ -79,3 +83,92 @@ timestamp.`,
7983

8084
return cmd
8185
}
86+
87+
type VestingData struct {
88+
StartTime int64 `json:"start_time"`
89+
Periods []InputPeriod `json:"periods"`
90+
}
91+
92+
type InputPeriod struct {
93+
Coins string `json:"coins"`
94+
Length int64 `json:"length_seconds"`
95+
}
96+
97+
// NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a
98+
// MsgCreatePeriodicVestingAccountCmd transaction.
99+
func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
100+
cmd := &cobra.Command{
101+
Use: "create-periodic-vesting-account [to_address] [periods_json_file]",
102+
Short: "Create a new periodic vesting account funded with an allocation of tokens.",
103+
Long: `A sequence of coins and period length in seconds. Periods are sequential, in that the duration of a period only starts at the end of the previous period. The duration of the first period starts upon account creation. For instance, the following periods.json file shows 20 "test" coins vesting 30 days apart from each other.
104+
Where periods.json contains:
105+
106+
An array of coin strings and unix epoch times for coins to vest
107+
{
108+
"start_time": 1625204910,
109+
"periods":
110+
[
111+
{
112+
"coins": "10test",
113+
"length_seconds": 2592000
114+
},
115+
{
116+
"coins": "10test",
117+
"length_seconds": 2592000
118+
}
119+
]
120+
}
121+
`,
122+
Args: cobra.ExactArgs(2),
123+
RunE: func(cmd *cobra.Command, args []string) error {
124+
clientCtx, err := client.GetClientTxContext(cmd)
125+
if err != nil {
126+
return err
127+
}
128+
129+
toAddr, err := sdk.AccAddressFromBech32(args[0])
130+
if err != nil {
131+
return err
132+
}
133+
134+
contents, err := ioutil.ReadFile(args[1])
135+
if err != nil {
136+
return err
137+
}
138+
139+
var vestingData VestingData
140+
141+
err = json.Unmarshal(contents, &vestingData)
142+
if err != nil {
143+
return err
144+
}
145+
146+
var periods []types.Period
147+
148+
for i, p := range vestingData.Periods {
149+
150+
amount, err := sdk.ParseCoinsNormalized(p.Coins)
151+
if err != nil {
152+
return err
153+
}
154+
155+
if p.Length < 0 {
156+
return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", p.Length, i)
157+
}
158+
period := types.Period{Length: p.Length, Amount: amount}
159+
periods = append(periods, period)
160+
}
161+
162+
msg := types.NewMsgCreatePeriodicVestingAccount(clientCtx.GetFromAddress(), toAddr, vestingData.StartTime, periods)
163+
if err := msg.ValidateBasic(); err != nil {
164+
return err
165+
}
166+
167+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
168+
},
169+
}
170+
171+
flags.AddTxFlagsToCmd(cmd)
172+
173+
return cmd
174+
}

0 commit comments

Comments
 (0)