Skip to content

Commit 54143fc

Browse files
zmanianqueencre
authored andcommitted
feat: periodic vesting msg, cherry-pick 147d798 cosmos#9596
(cherry picked from commit 5d01af4) (cherry picked from commit aefda6b) (cherry picked from commit 82c4293) (cherry picked from commit 071fe25)
1 parent c3c7984 commit 54143fc

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
@@ -581,12 +581,6 @@
581581

582582
- [Query](#cosmos.upgrade.v1beta1.Query)
583583

584-
- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
585-
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
586-
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)
587-
588-
- [Msg](#cosmos.vesting.v1beta1.Msg)
589-
590584
- [cosmos/vesting/v1beta1/vesting.proto](#cosmos/vesting/v1beta1/vesting.proto)
591585
- [BaseVestingAccount](#cosmos.vesting.v1beta1.BaseVestingAccount)
592586
- [ContinuousVestingAccount](#cosmos.vesting.v1beta1.ContinuousVestingAccount)
@@ -595,6 +589,14 @@
595589
- [PeriodicVestingAccount](#cosmos.vesting.v1beta1.PeriodicVestingAccount)
596590
- [PermanentLockedAccount](#cosmos.vesting.v1beta1.PermanentLockedAccount)
597591

592+
- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
593+
- [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount)
594+
- [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse)
595+
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
596+
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)
597+
598+
- [Msg](#cosmos.vesting.v1beta1.Msg)
599+
598600
- [Scalar Value Types](#scalar-value-types)
599601

600602

@@ -8324,62 +8326,6 @@ Since: cosmos-sdk 0.43 | GET|/cosmos/upgrade/v1beta1/module_versions|
83248326

83258327

83268328

8327-
<a name="cosmos/vesting/v1beta1/tx.proto"></a>
8328-
<p align="right"><a href="#top">Top</a></p>
8329-
8330-
## cosmos/vesting/v1beta1/tx.proto
8331-
8332-
8333-
8334-
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>
8335-
8336-
### MsgCreateVestingAccount
8337-
MsgCreateVestingAccount defines a message that enables creating a vesting
8338-
account.
8339-
8340-
8341-
| Field | Type | Label | Description |
8342-
| ----- | ---- | ----- | ----------- |
8343-
| `from_address` | [string](#string) | | |
8344-
| `to_address` | [string](#string) | | |
8345-
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
8346-
| `end_time` | [int64](#int64) | | |
8347-
| `delayed` | [bool](#bool) | | |
8348-
8349-
8350-
8351-
8352-
8353-
8354-
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>
8355-
8356-
### MsgCreateVestingAccountResponse
8357-
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
8358-
8359-
8360-
8361-
8362-
8363-
<!-- end messages -->
8364-
8365-
<!-- end enums -->
8366-
8367-
<!-- end HasExtensions -->
8368-
8369-
8370-
<a name="cosmos.vesting.v1beta1.Msg"></a>
8371-
8372-
### Msg
8373-
Msg defines the bank Msg service.
8374-
8375-
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
8376-
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
8377-
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |
8378-
8379-
<!-- end services -->
8380-
8381-
8382-
83838329
<a name="cosmos/vesting/v1beta1/vesting.proto"></a>
83848330
<p align="right"><a href="#top">Top</a></p>
83858331

@@ -8503,6 +8449,92 @@ Since: cosmos-sdk 0.43
85038449

85048450

85058451

8452+
<a name="cosmos/vesting/v1beta1/tx.proto"></a>
8453+
<p align="right"><a href="#top">Top</a></p>
8454+
8455+
## cosmos/vesting/v1beta1/tx.proto
8456+
8457+
8458+
8459+
<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount"></a>
8460+
8461+
### MsgCreatePeriodicVestingAccount
8462+
MsgCreatePeriodicVestingAccount defines a message that enables creating a periodic vesting
8463+
account.
8464+
8465+
8466+
| Field | Type | Label | Description |
8467+
| ----- | ---- | ----- | ----------- |
8468+
| `from_address` | [string](#string) | | |
8469+
| `to_address` | [string](#string) | | |
8470+
| `start_time` | [int64](#int64) | | |
8471+
| `vesting_periods` | [Period](#cosmos.vesting.v1beta1.Period) | repeated | |
8472+
8473+
8474+
8475+
8476+
8477+
8478+
<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse"></a>
8479+
8480+
### MsgCreatePeriodicVestingAccountResponse
8481+
MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type.
8482+
8483+
8484+
8485+
8486+
8487+
8488+
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>
8489+
8490+
### MsgCreateVestingAccount
8491+
MsgCreateVestingAccount defines a message that enables creating a vesting
8492+
account.
8493+
8494+
8495+
| Field | Type | Label | Description |
8496+
| ----- | ---- | ----- | ----------- |
8497+
| `from_address` | [string](#string) | | |
8498+
| `to_address` | [string](#string) | | |
8499+
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
8500+
| `end_time` | [int64](#int64) | | |
8501+
| `delayed` | [bool](#bool) | | |
8502+
8503+
8504+
8505+
8506+
8507+
8508+
<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>
8509+
8510+
### MsgCreateVestingAccountResponse
8511+
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
8512+
8513+
8514+
8515+
8516+
8517+
<!-- end messages -->
8518+
8519+
<!-- end enums -->
8520+
8521+
<!-- end HasExtensions -->
8522+
8523+
8524+
<a name="cosmos.vesting.v1beta1.Msg"></a>
8525+
8526+
### Msg
8527+
Msg defines the bank Msg service.
8528+
8529+
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
8530+
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
8531+
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |
8532+
| `CreatePeriodicVestingAccount` | [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount) | [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse) | CreatePeriodicVestingAccount defines a method that enables creating a periodic vesting account. | |
8533+
8534+
<!-- end services -->
8535+
8536+
8537+
85068538
## Scalar Value Types
85078539

85088540
| .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)