@@ -3,21 +3,18 @@ package main
33import (
44 "log"
55 "os"
6- "strconv"
76
87 "github.com/Sifchain/sifnode/app"
98 "github.com/Sifchain/sifnode/x/margin/types"
109 "github.com/cosmos/cosmos-sdk/client"
1110 "github.com/cosmos/cosmos-sdk/client/config"
1211 "github.com/cosmos/cosmos-sdk/client/flags"
1312 "github.com/cosmos/cosmos-sdk/client/tx"
14- "github.com/cosmos/cosmos-sdk/crypto/hd"
1513 "github.com/cosmos/cosmos-sdk/crypto/keyring"
1614 "github.com/cosmos/cosmos-sdk/server"
1715 svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
1816 sdk "github.com/cosmos/cosmos-sdk/types"
1917 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
20- banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
2118 "github.com/spf13/cobra"
2219)
2320
@@ -75,6 +72,9 @@ func run(cmd *cobra.Command, args []string) error {
7572
7673 txf := tx .NewFactoryCLI (clientCtx , cmd .Flags ())
7774 key , err := txf .Keybase ().Key (clientCtx .GetFromName ())
75+ if err != nil {
76+ panic (err )
77+ }
7878
7979 accountNumber , seq , err := txf .AccountRetriever ().GetAccountNumberSequence (clientCtx , key .GetAddress ())
8080 if err != nil {
@@ -84,7 +84,7 @@ func run(cmd *cobra.Command, args []string) error {
8484 txf .WithAccountNumber (accountNumber )
8585
8686 for a := 0 ; a < positions ; a ++ {
87- txf = txf .WithSequence (seq + uint64 (a ))
87+ txf = txf .WithSequence (seq + uint64 (a )) // nolint:gosec
8888 err := broadcastTrade (clientCtx , txf , key )
8989 if err != nil {
9090 panic (err )
@@ -94,113 +94,6 @@ func run(cmd *cobra.Command, args []string) error {
9494 return nil
9595}
9696
97- func generateAddresses (addresses chan keyring.Info , keys keyring.Keyring , num int ) {
98- for a := 0 ; a < num ; a ++ {
99- info , _ , err := keys .NewMnemonic ("funded_" + strconv .Itoa (a ), keyring .English , hd .CreateHDPath (118 , 0 , 0 ).String (), keyring .DefaultBIP39Passphrase , hd .Secp256k1 )
100- if err != nil {
101- log .Printf ("%s" , err )
102- }
103-
104- addresses <- info
105- }
106- }
107-
108- func newAccountFunder (funded chan keyring.Info , clientCtx client.Context , txf tx.Factory , fromAddress sdk.AccAddress , coins sdk.Coins ) func (keyring.Info ) {
109- accountNumber , seq , err := txf .AccountRetriever ().GetAccountNumberSequence (clientCtx , fromAddress )
110- if err != nil {
111- panic (err )
112- }
113-
114- log .Printf ("Got account num(%d)/seq(%d) for address %s" , accountNumber , seq , fromAddress .String ())
115-
116- return func (key keyring.Info ) {
117- msg := banktypes .NewMsgSend (fromAddress , key .GetAddress (), coins )
118-
119- txf = txf .WithAccountNumber (accountNumber ).WithSequence (seq )
120-
121- txb , err := tx .BuildUnsignedTx (txf , msg )
122- if err != nil {
123- panic (err )
124- }
125-
126- err = tx .Sign (txf , "faucet" , txb , true )
127- if err != nil {
128- panic (err )
129- }
130-
131- txBytes , err := clientCtx .TxConfig .TxEncoder ()(txb .GetTx ())
132- if err != nil {
133- panic (err )
134- }
135-
136- res , err := clientCtx .WithSimulation (true ).WithBroadcastMode ("block" ).BroadcastTx (txBytes )
137- if err != nil {
138- log .Printf ("ERR %s" , err )
139- } else {
140- log .Printf ("Funded address %s" , key .GetAddress ().String ())
141- }
142-
143- log .Print (res )
144-
145- seq ++
146- funded <- key
147- }
148- }
149-
150- func newFaucet (keys keyring.Keyring , from , mnemonic string ) (keyring.Info , error ) {
151- return keys .NewAccount (from , mnemonic , keyring .DefaultBIP39Passphrase , hd .CreateHDPath (118 , 0 , 0 ).String (), hd .Secp256k1 )
152- }
153-
154- func buildMsgs (traders []sdk.AccAddress ) []* types.MsgOpen {
155- collateralAsset := "rowan"
156- collateralAmount := uint64 (100 )
157- borrowAsset := "ceth"
158-
159- var msgs []* types.MsgOpen
160- for i := range traders {
161- log .Printf ("%s" , traders [i ].String ())
162- msgs = append (msgs , & types.MsgOpen {
163- Signer : traders [i ].String (),
164- CollateralAsset : collateralAsset ,
165- CollateralAmount : sdk .NewUint (collateralAmount ),
166- BorrowAsset : borrowAsset ,
167- Position : types .Position_LONG ,
168- })
169- }
170-
171- return msgs
172- }
173-
174- func buildTxs (txf tx.Factory , msgs []* types.MsgOpen ) []client.TxBuilder {
175- var txs []client.TxBuilder
176- for i := range msgs {
177- txb , err := tx .BuildUnsignedTx (txf , msgs [i ])
178- if err != nil {
179- panic (err )
180- }
181- err = tx .Sign (txf , msgs [i ].Signer , txb , true )
182- if err != nil {
183- panic (err )
184- }
185- txs = append (txs , txb )
186- }
187- return txs
188- }
189-
190- func sendTxs (clientCtx client.Context , txs []client.TxBuilder ) {
191- for t := range txs {
192- txBytes , err := clientCtx .TxConfig .TxEncoder ()(txs [t ].GetTx ())
193- if err != nil {
194- panic (err )
195- }
196-
197- _ , err = clientCtx .WithSimulation (true ).WithBroadcastMode ("block" ).BroadcastTx (txBytes )
198- if err != nil {
199- log .Printf ("ERR %s" , err )
200- }
201- }
202- }
203-
20497func broadcastTrade (clientCtx client.Context , txf tx.Factory , key keyring.Info ) error {
20598 collateralAsset := "rowan"
20699 collateralAmount := uint64 (100 )
0 commit comments