-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #5865: Proto Client Migration: x/bank
- Loading branch information
Showing
32 changed files
with
1,839 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package tx | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/spf13/viper" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AccountRetriever defines the interfaces required for use by the Factory to | ||
// ensure an account exists and to be able to query for account fields necessary | ||
// for signing. | ||
type AccountRetriever interface { | ||
EnsureExists(addr sdk.AccAddress) error | ||
GetAccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error) | ||
} | ||
|
||
// Factory defines a client transaction factory that facilitates generating and | ||
// signing an application-specific transaction. | ||
type Factory struct { | ||
keybase keyring.Keybase | ||
txGenerator Generator | ||
accountRetriever AccountRetriever | ||
accountNumber uint64 | ||
sequence uint64 | ||
gas uint64 | ||
gasAdjustment float64 | ||
simulateAndExecute bool | ||
chainID string | ||
memo string | ||
fees sdk.Coins | ||
gasPrices sdk.DecCoins | ||
} | ||
|
||
func NewFactoryFromCLI(input io.Reader) Factory { | ||
kb, err := keyring.NewKeyring( | ||
sdk.KeyringServiceName(), | ||
viper.GetString(flags.FlagKeyringBackend), | ||
viper.GetString(flags.FlagHome), | ||
input, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
f := Factory{ | ||
keybase: kb, | ||
accountNumber: viper.GetUint64(flags.FlagAccountNumber), | ||
sequence: viper.GetUint64(flags.FlagSequence), | ||
gas: flags.GasFlagVar.Gas, | ||
gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment), | ||
simulateAndExecute: flags.GasFlagVar.Simulate, | ||
chainID: viper.GetString(flags.FlagChainID), | ||
memo: viper.GetString(flags.FlagMemo), | ||
} | ||
|
||
f = f.WithFees(viper.GetString(flags.FlagFees)) | ||
f = f.WithGasPrices(viper.GetString(flags.FlagGasPrices)) | ||
|
||
return f | ||
} | ||
|
||
// nolint | ||
func (f Factory) AccountNumber() uint64 { return f.accountNumber } | ||
func (f Factory) Sequence() uint64 { return f.sequence } | ||
func (f Factory) Gas() uint64 { return f.gas } | ||
func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } | ||
func (f Factory) Keybase() keyring.Keybase { return f.keybase } | ||
func (f Factory) ChainID() string { return f.chainID } | ||
func (f Factory) Memo() string { return f.memo } | ||
func (f Factory) Fees() sdk.Coins { return f.fees } | ||
func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } | ||
func (f Factory) AccountRetriever() AccountRetriever { return f.accountRetriever } | ||
|
||
// SimulateAndExecute returns the option to simulate and then execute the transaction | ||
// using the gas from the simulation results | ||
func (f Factory) SimulateAndExecute() bool { return f.simulateAndExecute } | ||
|
||
// WithTxGenerator returns a copy of the Factory with an updated Generator. | ||
func (f Factory) WithTxGenerator(g Generator) Factory { | ||
f.txGenerator = g | ||
return f | ||
} | ||
|
||
// WithAccountRetriever returns a copy of the Factory with an updated AccountRetriever. | ||
func (f Factory) WithAccountRetriever(ar AccountRetriever) Factory { | ||
f.accountRetriever = ar | ||
return f | ||
} | ||
|
||
// WithChainID returns a copy of the Factory with an updated chainID. | ||
func (f Factory) WithChainID(chainID string) Factory { | ||
f.chainID = chainID | ||
return f | ||
} | ||
|
||
// WithGas returns a copy of the Factory with an updated gas value. | ||
func (f Factory) WithGas(gas uint64) Factory { | ||
f.gas = gas | ||
return f | ||
} | ||
|
||
// WithFees returns a copy of the Factory with an updated fee. | ||
func (f Factory) WithFees(fees string) Factory { | ||
parsedFees, err := sdk.ParseCoins(fees) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
f.fees = parsedFees | ||
return f | ||
} | ||
|
||
// WithGasPrices returns a copy of the Factory with updated gas prices. | ||
func (f Factory) WithGasPrices(gasPrices string) Factory { | ||
parsedGasPrices, err := sdk.ParseDecCoins(gasPrices) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
f.gasPrices = parsedGasPrices | ||
return f | ||
} | ||
|
||
// WithKeybase returns a copy of the Factory with updated Keybase. | ||
func (f Factory) WithKeybase(keybase keyring.Keybase) Factory { | ||
f.keybase = keybase | ||
return f | ||
} | ||
|
||
// WithSequence returns a copy of the Factory with an updated sequence number. | ||
func (f Factory) WithSequence(sequence uint64) Factory { | ||
f.sequence = sequence | ||
return f | ||
} | ||
|
||
// WithMemo returns a copy of the Factory with an updated memo. | ||
func (f Factory) WithMemo(memo string) Factory { | ||
f.memo = memo | ||
return f | ||
} | ||
|
||
// WithAccountNumber returns a copy of the Factory with an updated account number. | ||
func (f Factory) WithAccountNumber(accnum uint64) Factory { | ||
f.accountNumber = accnum | ||
return f | ||
} | ||
|
||
// WithGasAdjustment returns a copy of the Factory with an updated gas adjustment. | ||
func (f Factory) WithGasAdjustment(gasAdj float64) Factory { | ||
f.gasAdjustment = gasAdj | ||
return f | ||
} | ||
|
||
// WithSimulateAndExecute returns a copy of the Factory with an updated gas | ||
// simulation value. | ||
func (f Factory) WithSimulateAndExecute(sim bool) Factory { | ||
f.simulateAndExecute = sim | ||
return f | ||
} |
Oops, something went wrong.