-
Notifications
You must be signed in to change notification settings - Fork 1
/
changeBuyerBid.go
executable file
·61 lines (47 loc) · 1.76 KB
/
changeBuyerBid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cli
import (
"github.com/cosmos/cosmos-sdk/client/context"
cTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/commitHub/commitBlockchain/codec"
"github.com/commitHub/commitBlockchain/modules/auth"
"github.com/commitHub/commitBlockchain/modules/auth/client/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/commitHub/commitBlockchain/types"
negotiationTypes "github.com/commitHub/commitBlockchain/modules/negotiation/internal/types"
)
func ChangeBuyerBidCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "change-buyer-bid",
Short: "Change or create a buyer negotiation bid",
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
toStr := viper.GetString(FlagTo)
to, err := cTypes.AccAddressFromBech32(toStr)
if err != nil {
return nil
}
bid := viper.GetInt64(FlagBid)
time := viper.GetInt64(FlagTime)
hashStr := viper.GetString(FlagPegHash)
pegHashHex, err := types.GetAssetPegHashHex(hashStr)
negotiationID := negotiationTypes.NegotiationID(append(append(cliCtx.GetFromAddress().Bytes(), to.Bytes()...), pegHashHex...))
proposedNegotiation := &negotiationTypes.BaseNegotiation{
NegotiationID: negotiationID,
BuyerAddress: cliCtx.GetFromAddress(),
SellerAddress: to,
PegHash: pegHashHex,
Bid: bid,
Time: time,
}
msg := negotiationTypes.BuildMsgChangeBuyerBid(proposedNegotiation)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []cTypes.Msg{msg})
},
}
cmd.Flags().AddFlagSet(fsTo)
cmd.Flags().AddFlagSet(fsPegHash)
cmd.Flags().AddFlagSet(fsBid)
cmd.Flags().AddFlagSet(fsTime)
return cmd
}