diff --git a/x/metadata/client/cli/tx.go b/x/metadata/client/cli/tx.go index e8a0d29d76..18df359078 100644 --- a/x/metadata/client/cli/tx.go +++ b/x/metadata/client/cli/tx.go @@ -23,6 +23,8 @@ const ( FlagRequirePartyRollup = "require-party-rollup" AddSwitch = "add" RemoveSwitch = "remove" + FlagUsdMils = "usd-mils" + FlagVolume = "volume" ) // NewTxCmd is the top-level command for Metadata CLI transactions. @@ -134,7 +136,21 @@ func WriteScopeCmd() *cobra.Command { requirePartyRollup, ) - msg := types.NewMsgWriteScopeRequest(scope, signers) + usdMils, err := cmd.Flags().GetUint64(FlagUsdMils) + if err != nil { + return fmt.Errorf("incorrect value for %s flag. Accepted: 0 or greater value Error: %w", FlagUsdMils, err) + } + + volume, err := cmd.Flags().GetUint64(FlagVolume) + if err != nil { + return fmt.Errorf("incorrect value for %s flag. Accepted: 0 or greater value Error: %w", FlagVolume, err) + } + + if usdMils > 0 && volume == 0 { + return fmt.Errorf("incorrect value for %s flag. Must be positive number if %s flag has been set to positive value", FlagVolume, FlagUsdMils) + } + + msg := types.NewMsgWriteScopeRequest(scope, signers, usdMils, volume) err = msg.ValidateBasic() if err != nil { return err @@ -147,7 +163,8 @@ func WriteScopeCmd() *cobra.Command { cmd.Flags().Bool(FlagRequirePartyRollup, false, "Indicates party rollup is required in this scope") addSignersFlagToCmd(cmd) flags.AddTxFlagsToCmd(cmd) - + cmd.Flags().Uint64(FlagUsdMils, 0, "Indicates the net asset value of scope in usd mils, i.e. 1234 = $1.234") + cmd.Flags().Uint64(FlagVolume, 0, "Indicates the volume of the net asset value") return cmd } diff --git a/x/metadata/handler_test.go b/x/metadata/handler_test.go index 48efab6d21..53a84d3dfd 100644 --- a/x/metadata/handler_test.go +++ b/x/metadata/handler_test.go @@ -117,7 +117,7 @@ func (s *MetadataHandlerTestSuite) TestAddAndDeleteScopeDataAccess() { }, { "setup test with new scope", - types.NewMsgWriteScopeRequest(*scope, []string{s.user1}), + types.NewMsgWriteScopeRequest(*scope, []string{s.user1}, 0, 0), []string{s.user1}, "", }, @@ -277,7 +277,7 @@ func (s *MetadataHandlerTestSuite) TestAddAndDeleteScopeOwners() { }, { "setup test with new scope", - types.NewMsgWriteScopeRequest(*scope, []string{s.user1}), + types.NewMsgWriteScopeRequest(*scope, []string{s.user1}, 0, 0), []string{s.user1}, "", }, diff --git a/x/metadata/types/msg.go b/x/metadata/types/msg.go index 1ffc69e95b..0080ffa833 100644 --- a/x/metadata/types/msg.go +++ b/x/metadata/types/msg.go @@ -102,10 +102,12 @@ func stringsToAccAddresses(strings []string) []sdk.AccAddress { // ------------------ MsgWriteScopeRequest ------------------ // NewMsgWriteScopeRequest creates a new msg instance -func NewMsgWriteScopeRequest(scope Scope, signers []string) *MsgWriteScopeRequest { +func NewMsgWriteScopeRequest(scope Scope, signers []string, usdMils, volume uint64) *MsgWriteScopeRequest { return &MsgWriteScopeRequest{ Scope: scope, Signers: signers, + UsdMils: usdMils, + Volume: volume, } } diff --git a/x/metadata/types/msg_test.go b/x/metadata/types/msg_test.go index b9230fb027..3301e68148 100644 --- a/x/metadata/types/msg_test.go +++ b/x/metadata/types/msg_test.go @@ -228,7 +228,7 @@ func TestWriteScopeRoute(t *testing.T) { DataAccess: []string{"data_accessor"}, ValueOwnerAddress: "value_owner", } - var msg = NewMsgWriteScopeRequest(*scope, []string{}) + var msg = NewMsgWriteScopeRequest(*scope, []string{}, 0, 0) require.Equal(t, sdk.MsgTypeURL(msg), "/provenance.metadata.v1.MsgWriteScopeRequest") expectedYaml := `scope: @@ -245,6 +245,8 @@ func TestWriteScopeRoute(t *testing.T) { signers: [] scope_uuid: "" spec_uuid: "" +usdmils: 0 +volume: 0 ` bz, err := yaml.Marshal(msg) require.NoError(t, err, "yaml.Marshal(msg)") @@ -252,7 +254,7 @@ spec_uuid: "" bz, err = ModuleCdc.MarshalJSON(msg) require.NoError(t, err, "ModuleCdc.MarshalJSON(msg)") - assert.Equal(t, "{\"scope\":{\"scope_id\":\"scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp\",\"specification_id\":\"scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3\",\"owners\":[{\"address\":\"data_owner\",\"role\":\"PARTY_TYPE_OWNER\",\"optional\":false}],\"data_access\":[\"data_accessor\"],\"value_owner_address\":\"value_owner\",\"require_party_rollup\":false},\"signers\":[],\"scope_uuid\":\"\",\"spec_uuid\":\"\"}", string(bz)) + assert.Equal(t, "{\"scope\":{\"scope_id\":\"scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp\",\"specification_id\":\"scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3\",\"owners\":[{\"address\":\"data_owner\",\"role\":\"PARTY_TYPE_OWNER\",\"optional\":false}],\"data_access\":[\"data_accessor\"],\"value_owner_address\":\"value_owner\",\"require_party_rollup\":false},\"signers\":[],\"scope_uuid\":\"\",\"spec_uuid\":\"\",\"usd_mils\":\"0\",\"volume\":\"0\"}", string(bz)) } func TestWriteScopeValidation(t *testing.T) { @@ -263,7 +265,7 @@ func TestWriteScopeValidation(t *testing.T) { DataAccess: []string{"data_accessor"}, ValueOwnerAddress: "value_owner", } - var msg = NewMsgWriteScopeRequest(*scope, []string{"invalid"}) + var msg = NewMsgWriteScopeRequest(*scope, []string{"invalid"}, 0, 0) err := msg.ValidateBasic() require.EqualError(t, err, "invalid scope owners: invalid party address [data_owner]: decoding bech32 failed: invalid separator index -1") require.Panics(t, func() { msg.GetSigners() }, "panics due to invalid addresses") diff --git a/x/metadata/wasm/encode.go b/x/metadata/wasm/encode.go index b600ffd52d..2d9835e3bb 100644 --- a/x/metadata/wasm/encode.go +++ b/x/metadata/wasm/encode.go @@ -23,6 +23,10 @@ type WriteScope struct { Scope Scope `json:"scope"` // The signers' addresses. Signers []string `json:"signers"` + // UsdCents used to initialize the net asset value of scope + UsdMils uint64 `json:"usd_mils,omitempty"` + // Volume for the net asset value of scope + Volume uint64 `json:"volume,omitempty"` } // Encoder returns a smart contract message encoder for the metadata module. @@ -59,7 +63,7 @@ func (params *WriteScope) Encode() ([]sdk.Msg, error) { return nil, err } - msg := types.NewMsgWriteScopeRequest(*scope, params.Signers) + msg := types.NewMsgWriteScopeRequest(*scope, params.Signers, params.UsdMils, params.Volume) return []sdk.Msg{msg}, nil }