Skip to content

Commit

Permalink
bnsd: add support for cash extension configuration update (#1078)
Browse files Browse the repository at this point in the history
`bnsd` and `bnscli` were updated to support cash extension configuration
update.

Update `bnscli` gov provosal generation.

resolve #815
  • Loading branch information
husio authored Dec 16, 2019
1 parent 658682d commit 4cb0080
Show file tree
Hide file tree
Showing 41 changed files with 867 additions and 289 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## HEAD

- add cash configuration update message to `bnsd` transaction
- `x/account` extension added and installed in `cmd/bnsd`. `cmd/bnscli` was
updated to support the new extension.
- `datamigration` package added.
Expand Down
17 changes: 17 additions & 0 deletions cmd/bnscli/clitests/update_cash_configuration.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -e

bnscli update-cash-configuration \
-min-fee "0 IOV" \
| bnscli view

echo
echo

bnscli update-cash-configuration \
-collector 'seq:coll/bob/1' \
-min-fee "42 IOV" \
-owner 'seq:coll/alice/1' \
| bnscli view

32 changes: 32 additions & 0 deletions cmd/bnscli/clitests/update_cash_configuration.test.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Sum": {
"CashUpdateConfigurationMsg": {
"metadata": {
"schema": 1
},
"patch": {
"minimal_fee": {
"ticker": "IOV"
}
}
}
}
}

{
"Sum": {
"CashUpdateConfigurationMsg": {
"metadata": {
"schema": 1
},
"patch": {
"owner": "497FC2900ECA31B662691DD8B14F87BAF3C841DF",
"collector_address": "532286374CB9C9442FA1EAF0B352F91F1D79540B",
"minimal_fee": {
"whole": 42,
"ticker": "IOV"
}
}
}
}
}
31 changes: 31 additions & 0 deletions cmd/bnscli/cmd_cash.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ import (
"github.com/iov-one/weave/x/cash"
)

func cmdUpdateCashConfiguration(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Create a transaction for updating cash extension configuration.
`)
fl.PrintDefaults()
}
var (
ownerFl = flAddress(fl, "owner", "", "A new configuration owner.")
collectorFl = flAddress(fl, "collector", "", "A new collector address.")
minFeeFl = flCoin(fl, "min-fee", "1 IOV", "A new minimal fee value.")
)
fl.Parse(args)

tx := &bnsd.Tx{
Sum: &bnsd.Tx_CashUpdateConfigurationMsg{
CashUpdateConfigurationMsg: &cash.UpdateConfigurationMsg{
Metadata: &weave.Metadata{Schema: 1},
Patch: &cash.Configuration{
Owner: *ownerFl,
CollectorAddress: *collectorFl,
MinimalFee: *minFeeFl,
},
},
},
}
_, err := writeTx(output, tx)
return err
}

func cmdSendTokens(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
Expand Down
49 changes: 41 additions & 8 deletions cmd/bnscli/cmd_gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/iov-one/weave"
bnsd "github.com/iov-one/weave/cmd/bnsd/app"
"github.com/iov-one/weave/cmd/bnsd/x/username"
"github.com/iov-one/weave/datamigration"
"github.com/iov-one/weave/migration"
"github.com/iov-one/weave/x/cash"
"github.com/iov-one/weave/x/currency"
Expand Down Expand Up @@ -84,10 +85,6 @@ transaction (ie signatures) are being dropped.
option.Option = &bnsd.ProposalOptions_CurrencyCreateMsg{
CurrencyCreateMsg: msg,
}
case *msgfee.SetMsgFeeMsg:
option.Option = &bnsd.ProposalOptions_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: msg,
}
case *bnsd.ExecuteBatchMsg:
msgs, err := msg.MsgList()
if err != nil {
Expand All @@ -96,10 +93,6 @@ transaction (ie signatures) are being dropped.
var messages []bnsd.ExecuteProposalBatchMsg_Union
for _, m := range msgs {
switch m := m.(type) {
case *msgfee.SetMsgFeeMsg:
option.Option = &bnsd.ProposalOptions_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: m,
}
case *cash.SendMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_SendMsg{
Expand Down Expand Up @@ -148,6 +141,12 @@ transaction (ie signatures) are being dropped.
UsernameChangeTokenTargetsMsg: m,
},
})
case *username.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UsernameUpdateConfigurationMsg{
UsernameUpdateConfigurationMsg: m,
},
})
case *distribution.CreateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DistributionCreateMsg{
Expand Down Expand Up @@ -184,6 +183,24 @@ transaction (ie signatures) are being dropped.
GovCreateTextResolutionMsg: m,
},
})
case *msgfee.SetMsgFeeMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: m,
},
})
case *datamigration.ExecuteMigrationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DatamigrationExecuteMigrationMsg{
DatamigrationExecuteMigrationMsg: m,
},
})
case *cash.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_CashUpdateConfigurationMsg{
CashUpdateConfigurationMsg: m,
},
})
}
}
option.Option = &bnsd.ProposalOptions_ExecuteProposalBatchMsg{
Expand All @@ -203,6 +220,10 @@ transaction (ie signatures) are being dropped.
option.Option = &bnsd.ProposalOptions_UsernameChangeTokenTargetsMsg{
UsernameChangeTokenTargetsMsg: msg,
}
case *username.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_UsernameUpdateConfigurationMsg{
UsernameUpdateConfigurationMsg: msg,
}
case *distribution.CreateMsg:
option.Option = &bnsd.ProposalOptions_DistributionCreateMsg{
DistributionCreateMsg: msg,
Expand Down Expand Up @@ -231,6 +252,18 @@ transaction (ie signatures) are being dropped.
option.Option = &bnsd.ProposalOptions_GovCreateTextResolutionMsg{
GovCreateTextResolutionMsg: msg,
}
case *msgfee.SetMsgFeeMsg:
option.Option = &bnsd.ProposalOptions_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: msg,
}
case *datamigration.ExecuteMigrationMsg:
option.Option = &bnsd.ProposalOptions_DatamigrationExecuteMigrationMsg{
DatamigrationExecuteMigrationMsg: msg,
}
case *cash.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_CashUpdateConfigurationMsg{
CashUpdateConfigurationMsg: msg,
}
}

rawOption, err := option.Marshal()
Expand Down
7 changes: 4 additions & 3 deletions cmd/bnscli/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ func TestAddressFlag(t *testing.T) {
setup: func(fl *flag.FlagSet) *weave.Address {
return flAddress(fl, "x", "8d0d55645f1241a7a16d84fc9561a51d518c0d36", "")
},
args: []string{"-x", "zzzzzzzzzzzzz"},
wantDie: 0,
wantVal: fromHex(t, "8d0d55645f1241a7a16d84fc9561a51d518c0d36"),
args: []string{"-x", "zzzzzzzzzzzzz"},
wantDie: 0,
wantError: true,
wantVal: fromHex(t, "8d0d55645f1241a7a16d84fc9561a51d518c0d36"),
},
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/bnscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var commands = map[string]func(input io.Reader, output io.Writer, args []string)
"release-escrow": cmdReleaseEscrow,
"renew-account": cmdRenewAccount,
"renew-domain": cmdRenewDomain,
"replace-account-targets": cmdReplaceAccountTrarget,
"replace-account-msg-fees": cmdReplaceAccountMsgFees,
"replace-account-targets": cmdReplaceAccountTrarget,
"reset-revenue": cmdResetRevenue,
"resolve-username": cmdResolveUsername,
"send-tokens": cmdSendTokens,
Expand All @@ -73,6 +73,7 @@ var commands = map[string]func(input io.Reader, output io.Writer, args []string)
"transfer-account": cmdTransferAccount,
"transfer-domain": cmdTransferDomain,
"update-account-configuration": cmdUpdateAccountConfiguration,
"update-cash-configuration": cmdUpdateCashConfiguration,
"update-election-rule": cmdUpdateElectionRule,
"update-electorate": cmdUpdateElectorate,
"update-username-configuration": cmdUpdateUsernameConfiguration,
Expand Down
Loading

0 comments on commit 4cb0080

Please sign in to comment.