Distribute assets (#162)

* distributed & result msgs
* added DistributionResult
* added RDDL token conversion methods
* set proper validatoraddress within the testcases for e2e/dao
* set proper root dir for test cases
* fixed some wordings
---------

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-11-15 13:31:20 +01:00 committed by GitHub
parent 83d493dd94
commit a982abecf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 2689 additions and 269 deletions

View File

@ -4,7 +4,7 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/x/dao"
"github.com/planetmint/planetmint-go/x/dao/keeper"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
)
@ -22,7 +22,7 @@ func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
if ok {
logger.Debug("REISSUE: receive Proposal")
conf := config.GetConfig()
isValid := dao.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockHeight())
isValid := keeper.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockHeight())
if !isValid {
logger.Debug("REISSUE: Invalid Proposal")
return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx")

View File

@ -24,6 +24,11 @@ rpc-password = "{{ .PlmntConfig.RPCPassword }}"
issuance-service-dir = "{{ .PlmntConfig.IssuanceServiceDir }}"
reissuance-asset = "{{ .PlmntConfig.ReissuanceAsset }}"
validator-address = "{{ .PlmntConfig.ValidatorAddress }}"
distribution-address-inv = "{{ .PlmntConfig.DistributionAddrInv }}"
distribution-address-dao = "{{ .PlmntConfig.DistributionAddrDAO }}"
distribution-address-pop = "{{ .PlmntConfig.DistributionAddrPoP }}"
distribution-epochs = {{ .PlmntConfig.DistributionEpochs }}
`
// Config defines Planetmint's top level configuration
@ -41,6 +46,10 @@ type Config struct {
IssuanceServiceDir string `mapstructure:"issuance-service-dir" json:"issuance-service-dir"`
ReissuanceAsset string `mapstructure:"reissuance-asset" json:"reissuance-asset"`
ValidatorAddress string `mapstructure:"validator-address" json:"validator-address"`
DistributionAddrInv string `mapstructure:"distribution-address-inv" json:"distribution-address-inv"`
DistributionAddrDAO string `mapstructure:"distribution-address-dao" json:"distribution-address-dao"`
DistributionAddrPoP string `mapstructure:"distribution-address-pop" json:"distribution-address-pop"`
DistributionEpochs int `mapstructure:"distribution-epochs" json:"distribution-epochs"`
}
// cosmos-sdk wide global singleton
@ -61,10 +70,14 @@ func DefaultConfig() *Config {
RPCHost: "localhost",
RPCPort: 18884,
RPCUser: "user",
RPCPassword: "passwor",
RPCPassword: "password",
IssuanceServiceDir: "/opt/issuer_service",
ReissuanceAsset: "asset-id-or-name",
ReissuanceAsset: "7add40beb27df701e02ee85089c5bc0021bc813823fedb5f1dcb5debda7f3da9",
ValidatorAddress: "plmnt1w5dww335zhh98pzv783hqre355ck3u4w4hjxcx",
DistributionAddrInv: "vjTyRN2G42Yq3T5TJBecHj1dF1xdhKF89hKV4HJN3uXxUbaVGVR76hAfVRQqQCovWaEpar7G5qBBprFG",
DistributionAddrDAO: "vjU8eMzU3JbUWZEpVANt2ePJuPWSPixgjiSj2jDMvkVVQQi2DDnZuBRVX4Ygt5YGBf5zvTWCr1ntdqYH",
DistributionAddrPoP: "vjTvXCFSReRsZ7grdsAreRR12KuKpDw8idueQJK9Yh1BYS7ggAqgvCxCgwh13KGK6M52y37HUmvr4GdD",
DistributionEpochs: 17280, // CometBFT epochs of 5s equate 1 day (12*60*24)
}
}

View File

@ -46702,7 +46702,7 @@ paths:
type: string
rawtx:
type: string
txId:
txID:
type: string
blockHeight:
type: string
@ -46750,7 +46750,7 @@ paths:
type: string
rawtx:
type: string
txId:
txID:
type: string
blockHeight:
type: string
@ -75967,6 +75967,35 @@ definitions:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
planetmintgo.dao.DistributionOrder:
type: object
properties:
daoAddr:
type: string
daoAmount:
type: string
daoTxID:
type: string
investorAddr:
type: string
investorAmount:
type: string
investorTxID:
type: string
popAddr:
type: string
popAmount:
type: string
popTxID:
type: string
firstPop:
type: string
format: int64
lastPop:
type: string
format: int64
proposer:
type: string
planetmintgo.dao.MintRequest:
type: object
properties:
@ -75992,6 +76021,10 @@ definitions:
format: uint64
liquidTxHash:
type: string
planetmintgo.dao.MsgDistributionRequestResponse:
type: object
planetmintgo.dao.MsgDistributionResultResponse:
type: object
planetmintgo.dao.MsgMintTokenResponse:
type: object
planetmintgo.dao.MsgReissueRDDLProposalResponse:
@ -76029,7 +76062,7 @@ definitions:
type: string
rawtx:
type: string
txId:
txID:
type: string
blockHeight:
type: string
@ -76044,7 +76077,7 @@ definitions:
type: string
rawtx:
type: string
txId:
txID:
type: string
blockHeight:
type: string
@ -76110,7 +76143,7 @@ definitions:
type: string
rawtx:
type: string
txId:
txID:
type: string
blockHeight:
type: string

1
go.mod
View File

@ -27,6 +27,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529
google.golang.org/grpc v1.56.3
gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
sigs.k8s.io/yaml v1.3.0
)

1
go.sum
View File

@ -1644,6 +1644,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -0,0 +1,21 @@
syntax = "proto3";
package planetmintgo.dao;
option go_package = "github.com/planetmint/planetmint-go/x/dao/types";
message DistributionOrder {
string daoAddr = 1;
string daoAmount = 2;
string daoTxID = 3;
string investorAddr = 4;
string investorAmount = 5;
string investorTxID = 6;
string popAddr = 7;
string popAmount = 8;
string popTxID = 9;
int64 firstPop = 10;
int64 lastPop = 11;
string proposer = 12;
}

View File

@ -7,6 +7,6 @@ message Reissuance {
string proposer = 1;
string rawtx = 2;
string txId = 3;
string txID = 3;
int64 blockHeight = 4;
}

View File

@ -3,6 +3,7 @@ syntax = "proto3";
package planetmintgo.dao;
import "planetmintgo/dao/mint_request.proto";
import "planetmintgo/dao/distribution_order.proto";
import "planetmintgo/dao/params.proto";
import "amino/amino.proto";
import "gogoproto/gogo.proto";
@ -13,9 +14,11 @@ option go_package = "github.com/planetmint/planetmint-go/x/dao/types";
// Msg defines the Msg service.
service Msg {
rpc ReissueRDDLProposal (MsgReissueRDDLProposal) returns (MsgReissueRDDLProposalResponse);
rpc MintToken (MsgMintToken ) returns (MsgMintTokenResponse );
rpc ReissueRDDLResult (MsgReissueRDDLResult ) returns (MsgReissueRDDLResultResponse );
rpc ReissueRDDLProposal (MsgReissueRDDLProposal ) returns (MsgReissueRDDLProposalResponse );
rpc MintToken (MsgMintToken ) returns (MsgMintTokenResponse );
rpc ReissueRDDLResult (MsgReissueRDDLResult ) returns (MsgReissueRDDLResultResponse );
rpc DistributionResult (MsgDistributionResult ) returns (MsgDistributionResultResponse );
rpc DistributionRequest (MsgDistributionRequest) returns (MsgDistributionRequestResponse);
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
}
message MsgReissueRDDLProposal {
@ -37,11 +40,27 @@ message MsgMintTokenResponse {}
message MsgReissueRDDLResult {
string creator = 1;
string proposer = 2;
string txId = 3;
string txID = 3;
int64 blockHeight = 4;
}
message MsgReissueRDDLResultResponse {}
message MsgDistributionResult {
string creator = 1;
int64 lastPop = 2;
string daoTxID = 3;
string investorTxID = 4;
string popTxID = 5;
}
message MsgDistributionResultResponse {}
message MsgDistributionRequest {
string creator = 1;
DistributionOrder distribution = 2;
}
message MsgDistributionRequestResponse {}
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

View File

@ -5,26 +5,24 @@ import (
"encoding/json"
"fmt"
"os"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/planetmint/planetmint-go/testutil/sample"
"strconv"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/planetmint/planetmint-go/config"
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/planetmint/planetmint-go/testutil/sample"
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
)
@ -92,8 +90,6 @@ func (s *E2ETestSuite) SetupSuite() {
bankGenState.Balances = append(bankGenState.Balances, accountBalances...)
s.cfg.GenesisState[banktypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&bankGenState)
s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", conf.FeeDenom)
// Setup MintAddress parameter in genesis state
// use sample.Mnemonic to make mint address deterministic for test
s.cfg.Mnemonics = []string{sample.Mnemonic}
@ -107,6 +103,7 @@ func (s *E2ETestSuite) SetupSuite() {
daoGenState.Params.MintAddress = valAddr.String()
s.cfg.GenesisState[daotypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&daoGenState)
s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", conf.FeeDenom)
s.network = network.New(s.T(), s.cfg)
}
@ -259,3 +256,18 @@ func (s *E2ETestSuite) createValAccount(cfg network.Config) (address sdk.AccAddr
return addr, nil
}
func (s *E2ETestSuite) TestReissuance() {
conf := config.GetConfig()
val := s.network.Validators[0]
var err error
for i := 0; i < conf.PoPEpochs+10; i++ {
err = s.network.WaitForNextBlock()
s.Require().NoError(err)
}
var height int64
height, _ = s.network.LatestHeight()
intValue := strconv.FormatInt(height, 10)
_, _ = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue})
}

View File

@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/planetmint/planetmint-go/app"
"github.com/planetmint/planetmint-go/config"
)
type (
@ -37,7 +38,16 @@ func New(t *testing.T, configs ...Config) *Network {
} else {
cfg = configs[0]
}
net, err := network.New(t, t.TempDir(), cfg)
validatorTmpDir := t.TempDir()
//set the proper root dir for the test environment so that the abci.go logic works
appConfig := config.GetConfig()
appConfig.SetRoot(validatorTmpDir + "/node0/simd")
net, err := network.New(t, validatorTmpDir, cfg)
appConfig.ValidatorAddress = net.Validators[0].Address.String()
require.NoError(t, err)
_, err = net.WaitForHeight(1)
require.NoError(t, err)

View File

@ -31,7 +31,34 @@ func ReissueAsset(reissueTx string) (txid string, err error) {
errstr := stderr.String()
if err != nil || len(errstr) > 0 {
err = errors.New("reissuance of RDDL failed")
err = errors.New("reissuance of RDDL failed: " + errstr)
} else {
var txobj ReissueResult
err = json.Unmarshal(stdout.Bytes(), &txobj)
if err == nil {
txid = txobj.Txid
}
}
return txid, err
}
func DistributeAsset(address string, amount string) (txid string, err error) {
conf := config.GetConfig()
cmd := exec.Command("/usr/local/bin/elements-cli", "-rpcpassword="+conf.RPCPassword,
"-rpcuser="+conf.RPCUser, "-rpcport="+strconv.Itoa(conf.RPCPort), "-rpcconnect="+conf.RPCHost,
"sendtoaddress", address, amount, "", "", "false", "true", "null", "\"unset\"", "false",
"\""+conf.ReissuanceAsset+"\"")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
errstr := stderr.String()
if err != nil || len(errstr) > 0 {
errormessage := "distribution of RDDL failed for " + address
err = errors.New(errormessage)
} else {
var txobj ReissueResult
err = json.Unmarshal(stdout.Bytes(), &txobj)

View File

@ -1,13 +1,12 @@
package util
import (
"bytes"
"errors"
"os/exec"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, txUnsigned string, blockHeight int64) error {
@ -20,19 +19,8 @@ func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, txUnsign
"--from", sendingValidatorAddress, "-y",
proposerAddress, txUnsigned, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
// Start the command in a non-blocking way
err := cmd.Start()
errstr := stderr.String()
if err != nil || len(errstr) > 0 {
if err == nil {
err = errors.New(errstr)
}
}
return err
logger.Debug("REISSUE: create Proposal")
return cmd.Start()
}
func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blockHeight int64) error {
@ -43,17 +31,28 @@ func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID stri
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result",
"--from", sendingValidatorAddress, "-y",
proposerAddress, txID, strconv.FormatInt(blockHeight, 10))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
// Start the command in a non-blocking way
err := cmd.Start()
errstr := stderr.String()
if err != nil || len(errstr) > 0 {
if err == nil {
err = errors.New(errstr)
}
}
return err
logger.Debug("REISSUE: create Result")
return cmd.Start()
}
func SendRDDLDistributionRequest(ctx sdk.Context, distribution types.DistributionOrder) error {
logger := ctx.Logger()
// Construct the command
sendingValidatorAddress := config.GetConfig().ValidatorAddress
cmd := exec.Command("planetmint-god", "tx", "dao", "distribution-request",
"--from", sendingValidatorAddress, "-y", "'"+distribution.String()+"'")
logger.Debug("REISSUE: create Result")
return cmd.Start()
}
func SendRDDLDistributionResult(ctx sdk.Context, lastPoP string, daoTxid string, invTxid string, popTxid string) error {
logger := ctx.Logger()
// Construct the command
sendingValidatorAddress := config.GetConfig().ValidatorAddress
logger.Debug("REISSUE: create Result")
cmd := exec.Command("planetmint-god", "tx", "dao", "distribution-result",
"--from", sendingValidatorAddress, "-y",
lastPoP, daoTxid, invTxid, popTxid)
logger.Debug("REISSUE: create Result")
return cmd.Start()
}

26
util/rddl_token.go Normal file
View File

@ -0,0 +1,26 @@
package util
import "strconv"
var factor = 100000000.0
func RDDLToken2Uint(amount float64) uint64 {
return uint64(amount * factor)
}
func RDDLToken2Float(amount uint64) float64 {
return float64(amount) / factor
}
func RDDLTokenStringToFloat(amount string) (amountFloat float64, err error) {
amountFloat, err = strconv.ParseFloat(amount, 64)
return amountFloat, err
}
func RDDLTokenStringToUint(amount string) (amountUint uint64, err error) {
amountFloat, err := RDDLTokenStringToFloat(amount)
if err == nil {
amountUint = RDDLToken2Uint(amountFloat)
}
return amountUint, err
}

33
util/rddl_token_test.go Normal file
View File

@ -0,0 +1,33 @@
package util
import (
"testing"
"gotest.tools/assert"
)
func Test2FloatConvertion(t *testing.T) {
var expectedValue uint64 = 99869000000
value := RDDLToken2Uint(998.69)
assert.Equal(t, expectedValue, value)
}
func Test2UintConvertion(t *testing.T) {
expectedValue := 998.69
value := RDDLToken2Float(99869000000)
assert.Equal(t, expectedValue, value)
}
func TestStringToFloat(t *testing.T) {
expectedValue := 998.69
value, err := RDDLTokenStringToFloat("998.69")
assert.Equal(t, expectedValue, value)
assert.Equal(t, nil, err)
}
func TestStringToUint(t *testing.T) {
var expectedValue uint64 = 99869000000
value, err := RDDLTokenStringToUint("998.69")
assert.Equal(t, expectedValue, value)
assert.Equal(t, nil, err)
}

View File

@ -11,24 +11,38 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, _ keeper.Keeper) {
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
logger := ctx.Logger()
proposerAddress := req.Header.GetProposerAddress()
// Check if node is block proposer
if isPoPHeight(req.Header.GetHeight()) && util.IsValidatorBlockProposer(ctx, proposerAddress) {
// take the following actions only once, that's why we filter for the Block Proposer
if util.IsValidatorBlockProposer(ctx, proposerAddress) {
blockHeight := req.Header.GetHeight()
// TODO: implement PoP trigger
logger.Info("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
txUnsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
if isPoPHeight(blockHeight) {
logger.Debug("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
txUnsigned := keeper.GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
}
}
if isDistributionHeight(blockHeight) {
// initialize the distribution message
distribution, err := k.GetDistributionForReissuedTokens(ctx, blockHeight)
if err != nil {
logger.Error("error while computing the RDDL distribution ", err)
}
err = util.SendRDDLDistributionRequest(ctx, distribution)
if err != nil {
logger.Error("sending the distribution request failed")
}
}
}
}
func isPoPHeight(height int64) bool {
@ -36,6 +50,11 @@ func isPoPHeight(height int64) bool {
return height%int64(cfg.PoPEpochs) == 0
}
func isDistributionHeight(height int64) bool {
cfg := config.GetConfig()
return height%int64(cfg.DistributionEpochs) == 0
}
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
k.DistributeCollectedFees(ctx)
}

View File

@ -28,6 +28,8 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdReissueRDDLProposal())
cmd.AddCommand(CmdMintToken())
cmd.AddCommand(CmdReissueRDDLResult())
cmd.AddCommand(CmdDistributionResult())
cmd.AddCommand(CmdDistributionRequest())
cmd.AddCommand(CmdUpdateParams())
// this line is used by starport scaffolding # 1

View File

@ -0,0 +1,47 @@
package cli
import (
"strconv"
"encoding/json"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/planetmint/planetmint-go/x/dao/types"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdDistributionRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "distribution-request [distribution]",
Short: "Broadcast message distribution-request",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argDistribution := new(types.DistributionOrder)
err = json.Unmarshal([]byte(args[0]), argDistribution)
if err != nil {
return err
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgDistributionRequest(
clientCtx.GetFromAddress().String(),
argDistribution,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}

View File

@ -0,0 +1,52 @@
package cli
import (
"strconv"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/planetmint/planetmint-go/x/dao/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdDistributionResult() *cobra.Command {
cmd := &cobra.Command{
Use: "distribution-result [last-pop] [dao-txid] [investor-txid] [pop-txid]",
Short: "Broadcast message DistributionResult",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argLastPop, err := cast.ToInt64E(args[0])
if err != nil {
return err
}
argDaoTxid := args[1]
argInvestorTxid := args[2]
argPopTxid := args[3]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgDistributionResult(
clientCtx.GetFromAddress().String(),
argLastPop,
argDaoTxid,
argInvestorTxid,
argPopTxid,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}

View File

@ -0,0 +1,120 @@
package keeper
import (
"math/big"
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func (k Keeper) StoreDistributionOrder(ctx sdk.Context, distributionOrder types.DistributionOrder) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey))
appendValue := k.cdc.MustMarshal(&distributionOrder)
store.Set(getLastPopBytes(distributionOrder.LastPop), appendValue)
}
func (k Keeper) LookupDistributionOrder(ctx sdk.Context, lastPopHeight int64) (val types.DistributionOrder, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey))
distributionOrder := store.Get(getLastPopBytes(lastPopHeight))
if distributionOrder == nil {
return val, false
}
k.cdc.MustUnmarshal(distributionOrder, &val)
return val, true
}
func (k Keeper) GetLastDistributionOrder(ctx sdk.Context) (val types.DistributionOrder, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey))
iterator := store.ReverseIterator(nil, nil)
defer iterator.Close()
found = iterator.Valid()
if found {
distributionOrder := iterator.Value()
k.cdc.MustUnmarshal(distributionOrder, &val)
}
return val, found
}
// TODO to be integrated at a later stage
// func (k Keeper) getDistributionRequestPage(ctx sdk.Context, key []byte, offset uint64, page_size uint64, all bool, reverse bool) (distribution_orders []types.DistributionOrder) {
// store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey))
// iterator := store.Iterator(nil, nil)
// defer iterator.Close()
// if reverse {
// iterator = store.ReverseIterator(nil, nil)
// defer iterator.Close()
// }
// for ; iterator.Valid(); iterator.Next() {
// distribution_order := iterator.Value()
// var distribution_order_org types.DistributionOrder
// k.cdc.MustUnmarshal(distribution_order, &distribution_order_org)
// distribution_orders = append(distribution_orders, distribution_order_org)
// }
// return distribution_orders
// }
func getLastPopBytes(height int64) []byte {
// Adding 1 because 0 will be interpreted as nil, which is an invalid key
return big.NewInt(height + 1).Bytes()
}
func ComputeDistribution(lastReissuance int64, BlockHeight int64, amount uint64) (distribution types.DistributionOrder) {
conf := config.GetConfig()
distribution.FirstPop = lastReissuance
distribution.LastPop = BlockHeight
distribution.DaoAddr = conf.DistributionAddrDAO
distribution.InvestorAddr = conf.DistributionAddrInv
distribution.PopAddr = conf.DistributionAddrPoP
distribution.DaoAmount = strconv.FormatUint(uint64(float64(amount)*types.PercentageDao), 10)
distribution.InvestorAmount = strconv.FormatUint(uint64(float64(amount)*types.PercentageInvestor), 10)
distribution.PopAmount = strconv.FormatUint(uint64(float64(amount)*types.PercentagePop), 10)
return distribution
}
func getUint64FromTxString(ctx sdk.Context, tx string) (amount uint64, err error) {
subStrings := strings.Split(tx, " ")
if len(subStrings) < 3 {
ctx.Logger().Error("Reissue tx string is shorter than expected. " + tx)
} else {
value := subStrings[2]
amount, err = util.RDDLTokenStringToUint(value)
if err != nil {
ctx.Logger().Error("Reissue tx string value is invalid " + subStrings[2])
}
}
return amount, err
}
func (k Keeper) GetDistributionForReissuedTokens(ctx sdk.Context, blockHeight int64) (distribution types.DistributionOrder, err error) {
var lastPoP int64
lastDistributionOrder, found := k.GetLastDistributionOrder(ctx)
if found {
lastPoP = lastDistributionOrder.LastPop
}
reissuances := k.getReissuancesRange(ctx, lastPoP)
var overallAmount uint64
for index, obj := range reissuances {
if (index == 0 && lastPoP == 0 && obj.BlockHeight == 0) || //corner case (beginning of he chain)
(int64(lastPoP) < int64(obj.BlockHeight) && int64(obj.BlockHeight) <= blockHeight) {
amount, err := getUint64FromTxString(ctx, obj.Rawtx)
if err == nil {
overallAmount = overallAmount + amount
}
} else {
ctx.Logger().Info("%u %u %u", lastPoP, obj.BlockHeight, blockHeight)
}
}
distribution = ComputeDistribution(lastPoP, blockHeight, overallAmount)
return distribution, err
}

View File

@ -0,0 +1,82 @@
package keeper_test
import (
"fmt"
"strconv"
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/stretchr/testify/assert"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func createNDistributionOrder(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.DistributionOrder {
items := make([]types.DistributionOrder, n)
for i := range items {
amount := 10000
items[i].FirstPop = int64(i)*1000 + 1
items[i].LastPop = int64(i+1) * 1000
items[i].DaoAddr = fmt.Sprintf("DAO%v", i)
items[i].DaoAmount = fmt.Sprintf("%v", float64(amount)*types.PercentageDao)
items[i].InvestorAddr = fmt.Sprintf("INVESTOR%v", i)
items[i].InvestorAmount = fmt.Sprintf("%v", int64(float64(amount)*types.PercentageInvestor))
items[i].PopAddr = fmt.Sprintf("POP%v", i)
items[i].PopAmount = fmt.Sprintf("%v", float64(amount)*types.PercentagePop)
keeper.StoreDistributionOrder(ctx, items[i])
}
return items
}
func TestDistributionOrder(t *testing.T) {
keeper, ctx := keepertest.DaoKeeper(t)
items := createNDistributionOrder(keeper, ctx, 10)
for _, item := range items {
challenge, found := keeper.LookupDistributionOrder(ctx, item.LastPop)
assert.True(t, found)
assert.Equal(t, item, challenge)
}
lastDistribution, found := keeper.GetLastDistributionOrder(ctx)
assert.True(t, found)
assert.Equal(t, items[9], lastDistribution)
}
func TestTokenDistribution(t *testing.T) {
k, ctx := keepertest.DaoKeeper(t)
var reissuanceValue uint64 = 99869000000
reissuances := 1000
var Amount1stBatch uint64 = 781
var Amount2ndBatch uint64 = 219
_ = createNReissuances(k, ctx, reissuances)
distribution, err := k.GetDistributionForReissuedTokens(ctx, 780)
assert.Nil(t, err)
amount1, err1 := strconv.ParseUint(distribution.DaoAmount, 10, 64)
amount2, err2 := strconv.ParseUint(distribution.InvestorAmount, 10, 64)
amount3, err3 := strconv.ParseUint(distribution.PopAmount, 10, 64)
assert.Nil(t, err1)
assert.Nil(t, err2)
assert.Nil(t, err3)
sum := amount1 + amount2 + amount3
expSum := reissuanceValue * Amount1stBatch // add the [0] of the
assert.Equal(t, expSum, sum)
var lastDistribution types.DistributionOrder
lastDistribution.LastPop = 780
k.StoreDistributionOrder(ctx, lastDistribution)
lastDistribution, err0 := k.GetDistributionForReissuedTokens(ctx, 999)
assert.Nil(t, err0)
amount1, err1 = strconv.ParseUint(lastDistribution.DaoAmount, 10, 64)
amount2, err2 = strconv.ParseUint(lastDistribution.InvestorAmount, 10, 64)
amount3, err3 = strconv.ParseUint(lastDistribution.PopAmount, 10, 64)
assert.Nil(t, err1)
assert.Nil(t, err2)
assert.Nil(t, err3)
sum = amount1 + amount2 + amount3
expSum = reissuanceValue * Amount2ndBatch // add the [0] of the
assert.Equal(t, expSum, sum)
assert.Equal(t, uint64(reissuances), Amount1stBatch+Amount2ndBatch)
}

View File

@ -0,0 +1,43 @@
package keeper
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if validResult && msg.Distribution.GetProposer() == validatorIdentity {
// issue three distributions:
investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to Investors: ", err.Error())
}
popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to PoP: ", err.Error())
}
daoTx, err := util.DistributeAsset(msg.Distribution.DaoAddr, msg.Distribution.DaoAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to DAO: ", err.Error())
}
msg.Distribution.InvestorTxID = investorTx
msg.Distribution.PopTxID = popTx
msg.Distribution.DaoTxID = daoTx
lastPopString := strconv.FormatInt(msg.Distribution.LastPop, 10)
err = util.SendRDDLDistributionResult(ctx, lastPopString, daoTx, investorTx, popTx)
if err != nil {
ctx.Logger().Error("Distribution Request: could not send distribution result ", err.Error())
}
}
k.StoreDistributionOrder(ctx, *msg.GetDistribution())
return &types.MsgDistributionRequestResponse{}, nil
}

View File

@ -0,0 +1,26 @@
package keeper
import (
"context"
"strconv"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func (k msgServer) DistributionResult(goCtx context.Context, msg *types.MsgDistributionResult) (*types.MsgDistributionResultResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
distribution, found := k.LookupDistributionOrder(ctx, msg.GetLastPop())
if found {
distribution.DaoTxID = msg.DaoTxID
distribution.PopTxID = msg.PopTxID
distribution.InvestorTxID = msg.InvestorTxID
k.StoreDistributionOrder(ctx, distribution)
} else {
return nil, errorsmod.Wrapf(types.ErrDistributionNotFound, " for provided block height %s", strconv.FormatInt(msg.GetLastPop(), 10))
}
return &types.MsgDistributionResultResponse{}, nil
}

View File

@ -23,9 +23,8 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
_ = util.SendRDDLReissuanceResult(ctx, msg.GetProposer(), txID, msg.GetBlockHeight())
//TODO verify and resolve error
} else {
logger.Debug("REISSUE: Asset reissuance failure")
logger.Error("REISSUE: Asset reissuance failure: " + err.Error())
}
//TODO: reissuance need to be initiated otherwise
}
var reissuance types.Reissuance
@ -33,6 +32,5 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis
reissuance.Proposer = msg.GetProposer()
reissuance.Rawtx = msg.GetTx()
k.StoreReissuance(ctx, reissuance)
return &types.MsgReissueRDDLProposalResponse{}, nil
}

View File

@ -22,10 +22,10 @@ func (k msgServer) ReissueRDDLResult(goCtx context.Context, msg *types.MsgReissu
if reissuance.GetProposer() != msg.GetProposer() {
return nil, errorsmod.Wrapf(types.ErrInvalidProposer, " for provided block height %s", strconv.FormatInt(msg.GetBlockHeight(), 10))
}
if reissuance.GetTxId() != "" {
if reissuance.GetTxID() != "" {
return nil, errorsmod.Wrapf(types.ErrTXAlreadySet, " for provided block height %s", strconv.FormatInt(msg.GetBlockHeight(), 10))
}
reissuance.TxId = msg.GetTxId()
reissuance.TxID = msg.GetTxID()
k.StoreReissuance(ctx, reissuance)
return &types.MsgReissueRDDLResultResponse{}, nil

View File

@ -8,6 +8,15 @@ import (
"github.com/planetmint/planetmint-go/x/dao/types"
)
func GetReissuanceCommand(assetID string, _ int64) string {
return "reissueasset " + assetID + " 998.69000000"
}
func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool {
expected := "reissueasset " + assetID + " 998.69000000"
return reissuanceStr == expected
}
func (k Keeper) StoreReissuance(ctx sdk.Context, reissuance types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
appendValue := k.cdc.MustMarshal(&reissuance)
@ -24,6 +33,21 @@ func (k Keeper) LookupReissuance(ctx sdk.Context, height int64) (val types.Reiss
return val, true
}
func (k Keeper) getReissuancesRange(ctx sdk.Context, from int64) (reissuances []types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
iterator := store.Iterator(getReissuanceBytes(from), nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
reissuance := iterator.Value()
var reissuanceOrg types.Reissuance
k.cdc.MustUnmarshal(reissuance, &reissuanceOrg)
reissuances = append(reissuances, reissuanceOrg)
}
return reissuances
}
func (k Keeper) getReissuancesPage(ctx sdk.Context, _ []byte, _ uint64, _ uint64, _ bool, reverse bool) (reissuances []types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))

View File

@ -12,14 +12,14 @@ import (
"github.com/planetmint/planetmint-go/x/dao/types"
)
func createNReissuances(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Reissuance {
func createNReissuances(k *keeper.Keeper, ctx sdk.Context, n int) []types.Reissuance {
items := make([]types.Reissuance, n)
for i := range items {
items[i].BlockHeight = int64(i)
items[i].Proposer = fmt.Sprintf("proposer_%v", i)
items[i].Rawtx = fmt.Sprintf("rawtransaction_%v", i)
items[i].TxId = ""
keeper.StoreReissuance(ctx, items[i])
items[i].Rawtx = keeper.GetReissuanceCommand("asset_id", int64(i))
items[i].TxID = ""
k.StoreReissuance(ctx, items[i])
}
return items
}

View File

@ -32,10 +32,6 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgReissueRDDLResult int = 100
opWeightMsgUpdateParams = "op_weight_msg_update_params"
// TODO: Determine the simulation weight value
defaultWeightMsgUpdateParams int = 100
// this line is used by starport scaffolding # simapp/module/const
)
@ -86,17 +82,6 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
daosimulation.SimulateMsgReissueRDDLResult(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgUpdateParams int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUpdateParams, &weightMsgUpdateParams, nil,
func(_ *rand.Rand) {
weightMsgUpdateParams = defaultWeightMsgUpdateParams
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUpdateParams,
daosimulation.SimulateMsgUpdateParams(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
@ -121,14 +106,6 @@ func (am AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedPr
return nil
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgUpdateParams,
defaultWeightMsgUpdateParams,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
daosimulation.SimulateMsgUpdateParams(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}

View File

@ -0,0 +1,29 @@
package simulation
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func SimulateMsgDistributionRequest(
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgDistributionRequest{
Creator: simAccount.Address.String(),
}
// TODO: Handling the DistributionRequest simulation
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "DistributionRequest simulation not implemented"), nil, nil
}
}

View File

@ -0,0 +1,29 @@
package simulation
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func SimulateMsgDistributionResult(
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgDistributionResult{
Creator: simAccount.Address.String(),
}
// TODO: Handling the DistributionResult simulation
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "DistributionResult simulation not implemented"), nil, nil
}
}

View File

@ -11,6 +11,8 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgReissueRDDLProposal{}, "dao/ReissueRDDLProposal", nil)
cdc.RegisterConcrete(&MsgMintToken{}, "dao/MintToken", nil)
cdc.RegisterConcrete(&MsgReissueRDDLResult{}, "dao/ReissueRDDLResult", nil)
cdc.RegisterConcrete(&MsgDistributionResult{}, "dao/DistributionResult", nil)
cdc.RegisterConcrete(&MsgDistributionRequest{}, "dao/DistributionRequest", nil)
cdc.RegisterConcrete(&MsgUpdateParams{}, "dao/UpdateParams", nil)
// this line is used by starport scaffolding # 2
}
@ -24,6 +26,8 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgReissueRDDLResult{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgDistributionResult{},
&MsgDistributionRequest{},
&MsgUpdateParams{},
)
// this line is used by starport scaffolding # 3

5
x/dao/types/constants.go Normal file
View File

@ -0,0 +1,5 @@
package types
const PercentageDao float64 = 0.61
const PercentageInvestor float64 = 0.31
const PercentagePop float64 = 0.08

View File

@ -0,0 +1,855 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: planetmintgo/dao/distribution_order.proto
package types
import (
fmt "fmt"
proto "github.com/cosmos/gogoproto/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type DistributionOrder struct {
DaoAddr string `protobuf:"bytes,1,opt,name=daoAddr,proto3" json:"daoAddr,omitempty"`
DaoAmount string `protobuf:"bytes,2,opt,name=daoAmount,proto3" json:"daoAmount,omitempty"`
DaoTxID string `protobuf:"bytes,3,opt,name=daoTxID,proto3" json:"daoTxID,omitempty"`
InvestorAddr string `protobuf:"bytes,4,opt,name=investorAddr,proto3" json:"investorAddr,omitempty"`
InvestorAmount string `protobuf:"bytes,5,opt,name=investorAmount,proto3" json:"investorAmount,omitempty"`
InvestorTxID string `protobuf:"bytes,6,opt,name=investorTxID,proto3" json:"investorTxID,omitempty"`
PopAddr string `protobuf:"bytes,7,opt,name=popAddr,proto3" json:"popAddr,omitempty"`
PopAmount string `protobuf:"bytes,8,opt,name=popAmount,proto3" json:"popAmount,omitempty"`
PopTxID string `protobuf:"bytes,9,opt,name=popTxID,proto3" json:"popTxID,omitempty"`
FirstPop int64 `protobuf:"varint,10,opt,name=firstPop,proto3" json:"firstPop,omitempty"`
LastPop int64 `protobuf:"varint,11,opt,name=lastPop,proto3" json:"lastPop,omitempty"`
Proposer string `protobuf:"bytes,12,opt,name=proposer,proto3" json:"proposer,omitempty"`
}
func (m *DistributionOrder) Reset() { *m = DistributionOrder{} }
func (m *DistributionOrder) String() string { return proto.CompactTextString(m) }
func (*DistributionOrder) ProtoMessage() {}
func (*DistributionOrder) Descriptor() ([]byte, []int) {
return fileDescriptor_2bd326325e0d716d, []int{0}
}
func (m *DistributionOrder) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *DistributionOrder) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_DistributionOrder.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *DistributionOrder) XXX_Merge(src proto.Message) {
xxx_messageInfo_DistributionOrder.Merge(m, src)
}
func (m *DistributionOrder) XXX_Size() int {
return m.Size()
}
func (m *DistributionOrder) XXX_DiscardUnknown() {
xxx_messageInfo_DistributionOrder.DiscardUnknown(m)
}
var xxx_messageInfo_DistributionOrder proto.InternalMessageInfo
func (m *DistributionOrder) GetDaoAddr() string {
if m != nil {
return m.DaoAddr
}
return ""
}
func (m *DistributionOrder) GetDaoAmount() string {
if m != nil {
return m.DaoAmount
}
return ""
}
func (m *DistributionOrder) GetDaoTxID() string {
if m != nil {
return m.DaoTxID
}
return ""
}
func (m *DistributionOrder) GetInvestorAddr() string {
if m != nil {
return m.InvestorAddr
}
return ""
}
func (m *DistributionOrder) GetInvestorAmount() string {
if m != nil {
return m.InvestorAmount
}
return ""
}
func (m *DistributionOrder) GetInvestorTxID() string {
if m != nil {
return m.InvestorTxID
}
return ""
}
func (m *DistributionOrder) GetPopAddr() string {
if m != nil {
return m.PopAddr
}
return ""
}
func (m *DistributionOrder) GetPopAmount() string {
if m != nil {
return m.PopAmount
}
return ""
}
func (m *DistributionOrder) GetPopTxID() string {
if m != nil {
return m.PopTxID
}
return ""
}
func (m *DistributionOrder) GetFirstPop() int64 {
if m != nil {
return m.FirstPop
}
return 0
}
func (m *DistributionOrder) GetLastPop() int64 {
if m != nil {
return m.LastPop
}
return 0
}
func (m *DistributionOrder) GetProposer() string {
if m != nil {
return m.Proposer
}
return ""
}
func init() {
proto.RegisterType((*DistributionOrder)(nil), "planetmintgo.dao.DistributionOrder")
}
func init() {
proto.RegisterFile("planetmintgo/dao/distribution_order.proto", fileDescriptor_2bd326325e0d716d)
}
var fileDescriptor_2bd326325e0d716d = []byte{
// 309 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x51, 0xbf, 0x4e, 0xf3, 0x30,
0x10, 0xaf, 0xdb, 0xef, 0x6b, 0x1b, 0x53, 0x21, 0xc8, 0x64, 0x21, 0x64, 0x55, 0x1d, 0x50, 0x19,
0x48, 0x06, 0x9e, 0x00, 0xd4, 0xa5, 0x13, 0xa8, 0x62, 0x62, 0x41, 0x09, 0x0e, 0xc1, 0x52, 0x93,
0xb3, 0x1c, 0x07, 0x95, 0xb7, 0xe0, 0xb1, 0x18, 0x3b, 0x32, 0xa2, 0xe4, 0x29, 0xd8, 0x90, 0x2f,
0xa9, 0x9b, 0xb2, 0xdd, 0xef, 0x7e, 0xff, 0x6c, 0x1d, 0xbd, 0x54, 0xeb, 0x28, 0x4f, 0x4c, 0x26,
0x73, 0x93, 0x42, 0x28, 0x22, 0x08, 0x85, 0x2c, 0x8c, 0x96, 0x71, 0x69, 0x24, 0xe4, 0x4f, 0xa0,
0x45, 0xa2, 0x03, 0xa5, 0xc1, 0x80, 0x7f, 0xd2, 0x95, 0x06, 0x22, 0x82, 0xd9, 0x4f, 0x9f, 0x9e,
0x2e, 0x3a, 0xf2, 0x3b, 0xab, 0xf6, 0x19, 0x1d, 0x89, 0x08, 0x6e, 0x84, 0xd0, 0x8c, 0x4c, 0xc9,
0xdc, 0x5b, 0xed, 0xa0, 0x7f, 0x4e, 0x3d, 0x3b, 0x66, 0x50, 0xe6, 0x86, 0xf5, 0x91, 0xdb, 0x2f,
0x5a, 0xdf, 0xc3, 0x66, 0xb9, 0x60, 0x03, 0xe7, 0xb3, 0xd0, 0x9f, 0xd1, 0x89, 0xcc, 0xdf, 0x92,
0xc2, 0x80, 0xc6, 0xd8, 0x7f, 0x48, 0x1f, 0xec, 0xfc, 0x0b, 0x7a, 0xec, 0x70, 0x53, 0xf0, 0x1f,
0x55, 0x7f, 0xb6, 0xdd, 0x2c, 0xac, 0x1a, 0x1e, 0x66, 0x61, 0x1f, 0xa3, 0x23, 0x05, 0x0a, 0xab,
0x46, 0xcd, 0x4b, 0x5a, 0x68, 0x7f, 0x60, 0xc7, 0xa6, 0x60, 0xdc, 0xfc, 0xc0, 0x2d, 0x5a, 0x1f,
0xc6, 0x7a, 0xce, 0x87, 0x89, 0x67, 0x74, 0xfc, 0x22, 0x75, 0x61, 0xee, 0x41, 0x31, 0x3a, 0x25,
0xf3, 0xc1, 0xca, 0x61, 0xeb, 0x5a, 0x47, 0x0d, 0x75, 0x84, 0xd4, 0x0e, 0x5a, 0x97, 0xd2, 0xa0,
0xa0, 0x48, 0x34, 0x9b, 0x60, 0xa0, 0xc3, 0xb7, 0xcb, 0xcf, 0x8a, 0x93, 0x6d, 0xc5, 0xc9, 0x77,
0xc5, 0xc9, 0x47, 0xcd, 0x7b, 0xdb, 0x9a, 0xf7, 0xbe, 0x6a, 0xde, 0x7b, 0x0c, 0x53, 0x69, 0x5e,
0xcb, 0x38, 0x78, 0x86, 0x2c, 0xdc, 0x9f, 0xac, 0x33, 0x5e, 0xa5, 0x10, 0x6e, 0xf0, 0xd6, 0xe6,
0x5d, 0x25, 0x45, 0x3c, 0xc4, 0xfb, 0x5e, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x44, 0x71, 0x90,
0x55, 0x0c, 0x02, 0x00, 0x00,
}
func (m *DistributionOrder) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *DistributionOrder) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *DistributionOrder) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Proposer) > 0 {
i -= len(m.Proposer)
copy(dAtA[i:], m.Proposer)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.Proposer)))
i--
dAtA[i] = 0x62
}
if m.LastPop != 0 {
i = encodeVarintDistributionOrder(dAtA, i, uint64(m.LastPop))
i--
dAtA[i] = 0x58
}
if m.FirstPop != 0 {
i = encodeVarintDistributionOrder(dAtA, i, uint64(m.FirstPop))
i--
dAtA[i] = 0x50
}
if len(m.PopTxID) > 0 {
i -= len(m.PopTxID)
copy(dAtA[i:], m.PopTxID)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.PopTxID)))
i--
dAtA[i] = 0x4a
}
if len(m.PopAmount) > 0 {
i -= len(m.PopAmount)
copy(dAtA[i:], m.PopAmount)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.PopAmount)))
i--
dAtA[i] = 0x42
}
if len(m.PopAddr) > 0 {
i -= len(m.PopAddr)
copy(dAtA[i:], m.PopAddr)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.PopAddr)))
i--
dAtA[i] = 0x3a
}
if len(m.InvestorTxID) > 0 {
i -= len(m.InvestorTxID)
copy(dAtA[i:], m.InvestorTxID)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.InvestorTxID)))
i--
dAtA[i] = 0x32
}
if len(m.InvestorAmount) > 0 {
i -= len(m.InvestorAmount)
copy(dAtA[i:], m.InvestorAmount)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.InvestorAmount)))
i--
dAtA[i] = 0x2a
}
if len(m.InvestorAddr) > 0 {
i -= len(m.InvestorAddr)
copy(dAtA[i:], m.InvestorAddr)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.InvestorAddr)))
i--
dAtA[i] = 0x22
}
if len(m.DaoTxID) > 0 {
i -= len(m.DaoTxID)
copy(dAtA[i:], m.DaoTxID)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.DaoTxID)))
i--
dAtA[i] = 0x1a
}
if len(m.DaoAmount) > 0 {
i -= len(m.DaoAmount)
copy(dAtA[i:], m.DaoAmount)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.DaoAmount)))
i--
dAtA[i] = 0x12
}
if len(m.DaoAddr) > 0 {
i -= len(m.DaoAddr)
copy(dAtA[i:], m.DaoAddr)
i = encodeVarintDistributionOrder(dAtA, i, uint64(len(m.DaoAddr)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintDistributionOrder(dAtA []byte, offset int, v uint64) int {
offset -= sovDistributionOrder(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *DistributionOrder) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.DaoAddr)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.DaoAmount)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.DaoTxID)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.InvestorAddr)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.InvestorAmount)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.InvestorTxID)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.PopAddr)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.PopAmount)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
l = len(m.PopTxID)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
if m.FirstPop != 0 {
n += 1 + sovDistributionOrder(uint64(m.FirstPop))
}
if m.LastPop != 0 {
n += 1 + sovDistributionOrder(uint64(m.LastPop))
}
l = len(m.Proposer)
if l > 0 {
n += 1 + l + sovDistributionOrder(uint64(l))
}
return n
}
func sovDistributionOrder(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozDistributionOrder(x uint64) (n int) {
return sovDistributionOrder(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *DistributionOrder) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: DistributionOrder: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: DistributionOrder: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DaoAddr", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.DaoAddr = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DaoAmount", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.DaoAmount = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DaoTxID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.DaoTxID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field InvestorAddr", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.InvestorAddr = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field InvestorAmount", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.InvestorAmount = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field InvestorTxID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.InvestorTxID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 7:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field PopAddr", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.PopAddr = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 8:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field PopAmount", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.PopAmount = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 9:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field PopTxID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.PopTxID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 10:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field FirstPop", wireType)
}
m.FirstPop = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.FirstPop |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 11:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field LastPop", wireType)
}
m.LastPop = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.LastPop |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 12:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthDistributionOrder
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthDistributionOrder
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Proposer = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipDistributionOrder(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthDistributionOrder
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipDistributionOrder(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowDistributionOrder
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthDistributionOrder
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupDistributionOrder
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthDistributionOrder
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthDistributionOrder = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowDistributionOrder = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupDistributionOrder = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -8,15 +8,16 @@ import (
// x/dao module sentinel errors
var (
ErrInvalidMintAddress = errorsmod.Register(ModuleName, 2, "invalid mint address")
ErrMintFailed = errorsmod.Register(ModuleName, 3, "minting failed")
ErrTransferFailed = errorsmod.Register(ModuleName, 4, "transfer failed")
ErrInvalidAddress = errorsmod.Register(ModuleName, 5, "invalid address")
ErrAlreadyMinted = errorsmod.Register(ModuleName, 6, "already minted")
ErrWrongBlockHeight = errorsmod.Register(ModuleName, 7, "wrong block height")
ErrReissuanceNotFound = errorsmod.Register(ModuleName, 8, "reissuance not found")
ErrInvalidProposer = errorsmod.Register(ModuleName, 9, "invalid proposer")
ErrTXAlreadySet = errorsmod.Register(ModuleName, 10, "tx already set")
ErrReissuanceProposal = errorsmod.Register(ModuleName, 11, "invalid reissuance proposal")
ErrReissuanceFailed = errorsmod.Register(ModuleName, 12, "reissuance of RDDL failed")
ErrInvalidMintAddress = errorsmod.Register(ModuleName, 2, "invalid mint address")
ErrMintFailed = errorsmod.Register(ModuleName, 3, "minting failed")
ErrTransferFailed = errorsmod.Register(ModuleName, 4, "transfer failed")
ErrInvalidAddress = errorsmod.Register(ModuleName, 5, "invalid address")
ErrAlreadyMinted = errorsmod.Register(ModuleName, 6, "already minted")
ErrWrongBlockHeight = errorsmod.Register(ModuleName, 7, "wrong block height")
ErrReissuanceNotFound = errorsmod.Register(ModuleName, 8, "reissuance not found")
ErrInvalidProposer = errorsmod.Register(ModuleName, 9, "invalid proposer")
ErrTXAlreadySet = errorsmod.Register(ModuleName, 10, "tx already set")
ErrReissuanceProposal = errorsmod.Register(ModuleName, 11, "invalid reissuance proposal")
ErrReissuanceFailed = errorsmod.Register(ModuleName, 12, "reissuance of RDDL failed")
ErrDistributionNotFound = errorsmod.Register(ModuleName, 13, "distribution not found")
)

View File

@ -21,6 +21,10 @@ const (
ReissuanceBlockHeightKey = "Dao/ReissuanceBlockHeight"
DistributionKey = "Dao/Distribution"
PoPDistributionKey = "Dao/PoPDistribution"
ParamsKey = "Dao/Params"
)

View File

@ -0,0 +1,47 @@
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgDistributionRequest = "distribution_request"
var _ sdk.Msg = &MsgDistributionRequest{}
func NewMsgDistributionRequest(creator string, distribution *DistributionOrder) *MsgDistributionRequest {
return &MsgDistributionRequest{
Creator: creator,
Distribution: distribution,
}
}
func (msg *MsgDistributionRequest) Route() string {
return RouterKey
}
func (msg *MsgDistributionRequest) Type() string {
return TypeMsgDistributionRequest
}
func (msg *MsgDistributionRequest) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgDistributionRequest) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgDistributionRequest) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}

View File

@ -0,0 +1,50 @@
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgDistributionResult = "distribution_result"
var _ sdk.Msg = &MsgDistributionResult{}
func NewMsgDistributionResult(creator string, lastPop int64, daoTxID string, investorTxID string, popTxID string) *MsgDistributionResult {
return &MsgDistributionResult{
Creator: creator,
LastPop: lastPop,
DaoTxID: daoTxID,
InvestorTxID: investorTxID,
PopTxID: popTxID,
}
}
func (msg *MsgDistributionResult) Route() string {
return RouterKey
}
func (msg *MsgDistributionResult) Type() string {
return TypeMsgDistributionResult
}
func (msg *MsgDistributionResult) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgDistributionResult) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgDistributionResult) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}

View File

@ -1,47 +0,0 @@
package types
import (
"testing"
"github.com/cometbft/cometbft/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
)
func AccAddress() string {
pk := ed25519.GenPrivKey().PubKey()
addr := pk.Address()
return sdk.AccAddress(addr).String()
}
func TestMsgReissueRDDLProposal_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgReissueRDDLProposal
err error
}{
{
name: "invalid address",
msg: MsgReissueRDDLProposal{
Creator: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgReissueRDDLProposal{
Creator: AccAddress(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
})
}
}

View File

@ -14,7 +14,7 @@ func NewMsgReissueRDDLResult(creator string, proposer string, txID string, block
return &MsgReissueRDDLResult{
Creator: creator,
Proposer: proposer,
TxId: txID,
TxID: txID,
BlockHeight: blockHeight,
}
}

View File

@ -1,39 +0,0 @@
package types
import (
"testing"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
)
func TestMsgReissueRDDLResult_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgReissueRDDLResult
err error
}{
{
name: "invalid address",
msg: MsgReissueRDDLResult{
Creator: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgReissueRDDLResult{
Creator: AccAddress(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
})
}
}

View File

@ -25,7 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type Reissuance struct {
Proposer string `protobuf:"bytes,1,opt,name=proposer,proto3" json:"proposer,omitempty"`
Rawtx string `protobuf:"bytes,2,opt,name=rawtx,proto3" json:"rawtx,omitempty"`
TxId string `protobuf:"bytes,3,opt,name=txId,proto3" json:"txId,omitempty"`
TxID string `protobuf:"bytes,3,opt,name=txID,proto3" json:"txID,omitempty"`
BlockHeight int64 `protobuf:"varint,4,opt,name=blockHeight,proto3" json:"blockHeight,omitempty"`
}
@ -76,9 +76,9 @@ func (m *Reissuance) GetRawtx() string {
return ""
}
func (m *Reissuance) GetTxId() string {
func (m *Reissuance) GetTxID() string {
if m != nil {
return m.TxId
return m.TxID
}
return ""
}
@ -104,13 +104,13 @@ var fileDescriptor_35cf062bd4436e27 = []byte{
0x56, 0xa2, 0x97, 0x92, 0x98, 0xaf, 0x54, 0xc2, 0xc5, 0x15, 0x04, 0x57, 0x25, 0x24, 0xc5, 0xc5,
0x51, 0x50, 0x94, 0x5f, 0x90, 0x5f, 0x9c, 0x5a, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04,
0xe7, 0x0b, 0x89, 0x70, 0xb1, 0x16, 0x25, 0x96, 0x97, 0x54, 0x48, 0x30, 0x81, 0x25, 0x20, 0x1c,
0x21, 0x21, 0x2e, 0x96, 0x92, 0x0a, 0xcf, 0x14, 0x09, 0x66, 0xb0, 0x20, 0x98, 0x2d, 0xa4, 0xc0,
0x21, 0x21, 0x2e, 0x96, 0x92, 0x0a, 0x4f, 0x17, 0x09, 0x66, 0xb0, 0x20, 0x98, 0x2d, 0xa4, 0xc0,
0xc5, 0x9d, 0x94, 0x93, 0x9f, 0x9c, 0xed, 0x91, 0x9a, 0x99, 0x9e, 0x51, 0x22, 0xc1, 0xa2, 0xc0,
0xa8, 0xc1, 0x1c, 0x84, 0x2c, 0xe4, 0xe4, 0x79, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c,
0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72,
0x0c, 0x51, 0xfa, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x08, 0xc7,
0x22, 0x31, 0x75, 0xd3, 0xf3, 0xf5, 0x2b, 0xc0, 0xbe, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62,
0x03, 0xfb, 0xcc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xaf, 0x8f, 0xce, 0xfe, 0x00, 0x00,
0x03, 0xfb, 0xcc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x56, 0x20, 0xa3, 0x6c, 0xfe, 0x00, 0x00,
0x00,
}
@ -139,10 +139,10 @@ func (m *Reissuance) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x20
}
if len(m.TxId) > 0 {
i -= len(m.TxId)
copy(dAtA[i:], m.TxId)
i = encodeVarintReissuance(dAtA, i, uint64(len(m.TxId)))
if len(m.TxID) > 0 {
i -= len(m.TxID)
copy(dAtA[i:], m.TxID)
i = encodeVarintReissuance(dAtA, i, uint64(len(m.TxID)))
i--
dAtA[i] = 0x1a
}
@ -188,7 +188,7 @@ func (m *Reissuance) Size() (n int) {
if l > 0 {
n += 1 + l + sovReissuance(uint64(l))
}
l = len(m.TxId)
l = len(m.TxID)
if l > 0 {
n += 1 + l + sovReissuance(uint64(l))
}
@ -299,7 +299,7 @@ func (m *Reissuance) Unmarshal(dAtA []byte) error {
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TxId", wireType)
return fmt.Errorf("proto: wrong wireType = %d for field TxID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
@ -327,7 +327,7 @@ func (m *Reissuance) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.TxId = string(dAtA[iNdEx:postIndex])
m.TxID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 0 {

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
package dao
func GetReissuanceCommand(assetID string, _ int64) string {
return "reissueasset " + assetID + " 99869000000"
}
func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool {
expected := "reissueasset " + assetID + " 99869000000"
return reissuanceStr == expected
}