Skip to content

Commit

Permalink
feat: periodic vesting msg, cherry-pick 147d798 cosmos#9596
Browse files Browse the repository at this point in the history
(cherry picked from commit 5d01af4)
  • Loading branch information
zmanian authored and dongsam committed Mar 11, 2022
1 parent 33dbf6a commit aefda6b
Show file tree
Hide file tree
Showing 9 changed files with 898 additions and 90 deletions.
159 changes: 97 additions & 62 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,6 @@

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

- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)

- [Msg](#cosmos.vesting.v1beta1.Msg)

- [cosmos/vesting/v1beta1/vesting.proto](#cosmos/vesting/v1beta1/vesting.proto)
- [BaseVestingAccount](#cosmos.vesting.v1beta1.BaseVestingAccount)
- [ContinuousVestingAccount](#cosmos.vesting.v1beta1.ContinuousVestingAccount)
Expand All @@ -585,6 +579,14 @@
- [PeriodicVestingAccount](#cosmos.vesting.v1beta1.PeriodicVestingAccount)
- [PermanentLockedAccount](#cosmos.vesting.v1beta1.PermanentLockedAccount)

- [cosmos/vesting/v1beta1/tx.proto](#cosmos/vesting/v1beta1/tx.proto)
- [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount)
- [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse)
- [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount)
- [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse)

- [Msg](#cosmos.vesting.v1beta1.Msg)

- [Scalar Value Types](#scalar-value-types)


Expand Down Expand Up @@ -1268,6 +1270,9 @@ tags are stringified and the log is JSON decoded.
| `gas_used` | [int64](#int64) | | Amount of gas consumed by transaction. |
| `tx` | [google.protobuf.Any](#google.protobuf.Any) | | The request transaction bytes. |
| `timestamp` | [string](#string) | | Time of the previous block. For heights > 1, it's the weighted median of the timestamps of the valid votes in the block.LastCommit. For height == 1, it's genesis time. |
| `events` | [tendermint.abci.Event](#tendermint.abci.Event) | repeated | Events defines all the events emitted by processing a transaction. Note, these events include those emitted by processing all the messages and those emitted from the ante handler. Whereas Logs contains the events, with additional metadata, emitted only by processing the messages.

Since: cosmos-sdk 0.42.11, 0.44.5, 0.45 |



Expand Down Expand Up @@ -8105,62 +8110,6 @@ Since: cosmos-sdk 0.43 | GET|/cosmos/upgrade/v1beta1/module_versions|



<a name="cosmos/vesting/v1beta1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## cosmos/vesting/v1beta1/tx.proto



<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>

### MsgCreateVestingAccount
MsgCreateVestingAccount defines a message that enables creating a vesting
account.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | |
| `to_address` | [string](#string) | | |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `end_time` | [int64](#int64) | | |
| `delayed` | [bool](#bool) | | |






<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>

### MsgCreateVestingAccountResponse
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->


<a name="cosmos.vesting.v1beta1.Msg"></a>

### Msg
Msg defines the bank Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |

<!-- end services -->



<a name="cosmos/vesting/v1beta1/vesting.proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down Expand Up @@ -8284,6 +8233,92 @@ Since: cosmos-sdk 0.43



<a name="cosmos/vesting/v1beta1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## cosmos/vesting/v1beta1/tx.proto



<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount"></a>

### MsgCreatePeriodicVestingAccount
MsgCreateVestingAccount defines a message that enables creating a vesting
account.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | |
| `to_address` | [string](#string) | | |
| `start_time` | [int64](#int64) | | |
| `vesting_periods` | [Period](#cosmos.vesting.v1beta1.Period) | repeated | |






<a name="cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse"></a>

### MsgCreatePeriodicVestingAccountResponse
MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type.






<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccount"></a>

### MsgCreateVestingAccount
MsgCreateVestingAccount defines a message that enables creating a vesting
account.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | |
| `to_address` | [string](#string) | | |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `end_time` | [int64](#int64) | | |
| `delayed` | [bool](#bool) | | |






<a name="cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse"></a>

### MsgCreateVestingAccountResponse
MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->


<a name="cosmos.vesting.v1beta1.Msg"></a>

### Msg
Msg defines the bank Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | |
| `CreatePeriodicVestingAccount` | [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount) | [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse) | CreatePeriodicVestingAccount defines a method that enables creating a periodic vesting account. | |

<!-- end services -->



## Scalar Value Types

| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
Expand Down
20 changes: 19 additions & 1 deletion proto/cosmos/vesting/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cosmos.vesting.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/vesting/v1beta1/vesting.proto";

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

Expand All @@ -11,6 +12,9 @@ service Msg {
// CreateVestingAccount defines a method that enables creating a vesting
// account.
rpc CreateVestingAccount(MsgCreateVestingAccount) returns (MsgCreateVestingAccountResponse);
// CreatePeriodicVestingAccount defines a method that enables creating a
// periodic vesting account.
rpc CreatePeriodicVestingAccount(MsgCreatePeriodicVestingAccount) returns (MsgCreatePeriodicVestingAccountResponse);
}

// MsgCreateVestingAccount defines a message that enables creating a vesting
Expand All @@ -28,4 +32,18 @@ message MsgCreateVestingAccount {
}

// MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
message MsgCreateVestingAccountResponse {}
message MsgCreateVestingAccountResponse {}

// MsgCreateVestingAccount defines a message that enables creating a vesting
// account.
message MsgCreatePeriodicVestingAccount {
option (gogoproto.equal) = false;

string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""];
string to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""];
int64 start_time = 3 [(gogoproto.moretags) = "yaml:\"start_time\""];
repeated Period vesting_periods = 4 [(gogoproto.nullable) = false];
}

// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type.
message MsgCreatePeriodicVestingAccountResponse {}
22 changes: 22 additions & 0 deletions x/auth/vesting/client/cli/periods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"start_time": 1645403872,
"period":
[
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
}
]
}
22 changes: 22 additions & 0 deletions x/auth/vesting/client/cli/periods1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"start_time": 1645403872,
"period":
[
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
},
{
"coins": "1000000stake",
"length_seconds": 60000
}
]
}
91 changes: 91 additions & 0 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cli

import (
"encoding/json"
"fmt"
"io/ioutil"
"strconv"

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

txCmd.AddCommand(
NewMsgCreateVestingAccountCmd(),
NewMsgCreatePeriodicVestingAccountCmd(),
)

return txCmd
Expand Down Expand Up @@ -79,3 +83,90 @@ timestamp.`,

return cmd
}

type VestingData struct {
StartTime int64 `json:"start_time"`
Periods []InputPeriod `json:"periods"`
}

type InputPeriod struct {
Coins string `json:"coins"`
Length int64 `json:"length_seconds"`
}

// NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a
// MsgCreatePeriodicVestingAccountCmd transaction.
func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-periodic-vesting-account [to_address] [periods_json_file]",
Short: "Create a new vesting account funded with an allocation of tokens.",
Long: `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. For instance, the following periods.json file shows 20 "test" coins vesting 30 days apart from each other.
Where periods.json contains:
An array of coin strings and unix epoch times for coins to vest
{ "start_time": 1625204910,
"periods":[
{
"coins": "10test",
"length_seconds":2592000 //30 days
},
{
"coins": "10test",
"length_seconds":2592000 //30 days
},
]
}
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

toAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

contents, err := ioutil.ReadFile(args[1])
if err != nil {
return err
}

var vestingData VestingData

err = json.Unmarshal(contents, &vestingData)
if err != nil {
return err
}

var periods []types.Period

for i, p := range vestingData.Periods {

amount, err := sdk.ParseCoinsNormalized(p.Coins)
if err != nil {
return err
}

if p.Length < 0 {
return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", p.Length, i)
}
period := types.Period{Length: p.Length, Amount: amount}
periods = append(periods, period)
}

msg := types.NewMsgCreatePeriodicVestingAccount(clientCtx.GetFromAddress(), toAddr, vestingData.StartTime, periods)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
1 change: 1 addition & 0 deletions x/auth/vesting/client/cli/tx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package cli

0 comments on commit aefda6b

Please sign in to comment.