[transactions] Change default gasPrice to 1 from 0

pull/39/head
Edgar Aroutiounian 5 years ago
parent 9e71755447
commit 27de4d2de0
  1. 74
      cmd/subcommands/staking.go
  2. 4
      cmd/subcommands/transfer.go
  3. 1
      go.sum
  4. 11
      pkg/transaction/controller.go

@ -3,6 +3,8 @@ package cmd
import (
"errors"
"fmt"
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/rlp"
@ -10,7 +12,8 @@ import (
"github.com/harmony-one/go-sdk/pkg/ledger"
"github.com/harmony-one/go-sdk/pkg/rpc"
"github.com/harmony-one/go-sdk/pkg/store"
"strings"
"math/big"
"github.com/harmony-one/harmony/accounts"
"github.com/harmony-one/harmony/accounts/keystore"
@ -18,11 +21,10 @@ import (
"github.com/harmony-one/harmony/numeric"
staking "github.com/harmony-one/harmony/staking/types"
"github.com/spf13/cobra"
"math/big"
)
const (
blsPubKeySize = 48
blsPubKeySize = 48
)
var (
@ -31,7 +33,7 @@ var (
validatorWebsite string
validatorSecurityContact string
validatorDetails string
commisionRateStr string
commisionRateStr string
commisionMaxRateStr string
commisionMaxChangeRateStr string
minSelfDelegation float64
@ -59,7 +61,7 @@ func getNextNonce(messenger rpc.T) uint64 {
}
func createStakingTransaction(nonce uint64, f staking.StakeMsgFulfiller) (*staking.StakingTransaction, error) {
gasPrice := big.NewInt(int64(gasPrice))
gasPrice := big.NewInt(gasPrice)
gasPrice = gasPrice.Mul(gasPrice, big.NewInt(denominations.Nano))
//TODO: modify the gas limit calculation algorithm
@ -72,17 +74,19 @@ func createStakingTransaction(nonce uint64, f staking.StakeMsgFulfiller) (*staki
return stakingTx, err
}
func handleStakingTransaction(stakingTx *staking.StakingTransaction, networkHandler *rpc.HTTPMessenger, signerAddress oneAddress) error {
var ks *keystore.KeyStore
var acct *accounts.Account
var signed *staking.StakingTransaction
var err error
func handleStakingTransaction(
stakingTx *staking.StakingTransaction, networkHandler *rpc.HTTPMessenger, signerAddress oneAddress,
) error {
var ks *keystore.KeyStore
var acct *accounts.Account
var signed *staking.StakingTransaction
var err error
from := signerAddress.String()
if useLedgerWallet {
var signerAddr string
signed, signerAddr, err = ledger.SignStakingTx(stakingTx, chainName.chainID.Value)
signed, signerAddr, err = ledger.SignStakingTx(stakingTx, chainName.chainID.Value)
if err != nil {
return err
}
@ -125,7 +129,7 @@ func stakingSubCommands() []*cobra.Command {
Long: `
Create a new validator"
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
networkHandler, err := handlerForShard(0, node)
if err != nil {
return err
@ -161,17 +165,17 @@ Create a new validator"
copy(blsPubKey[:], []byte(stakingBlsPubKey))
return staking.DirectiveNewValidator, staking.NewValidator{
staking.Description {
staking.Description{
validatorName,
validatorIdentity,
validatorWebsite,
validatorSecurityContact,
validatorDetails,
},
staking.CommissionRates {
staking.CommissionRates{
commisionRate,
commisionMaxRate,
commisionMaxChangeRate },
commisionMaxChangeRate},
minSelfDel,
accounts.ParseAddrH(stakingAddress.String()),
blsPubKey,
@ -193,20 +197,19 @@ Create a new validator"
},
}
subCmdNewValidator.Flags().StringVar(&validatorName, "name", "","validator's name")
subCmdNewValidator.Flags().StringVar(&validatorName, "name", "", "validator's name")
subCmdNewValidator.Flags().StringVar(&validatorIdentity, "identity", "", "validator's identity")
subCmdNewValidator.Flags().StringVar(&validatorWebsite, "website", "", "validator's website")
subCmdNewValidator.Flags().StringVar(&validatorSecurityContact, "security-contact", "","validator's security contact")
subCmdNewValidator.Flags().StringVar(&validatorSecurityContact, "security-contact", "", "validator's security contact")
subCmdNewValidator.Flags().StringVar(&validatorDetails, "details", "", "validator's details")
subCmdNewValidator.Flags().StringVar(&commisionRateStr, "rate", "","commission rate")
subCmdNewValidator.Flags().StringVar(&commisionMaxRateStr, "max-rate","","commision max rate")
subCmdNewValidator.Flags().StringVar(&commisionMaxChangeRateStr, "max-change-rate","","commission max change amount")
subCmdNewValidator.Flags().StringVar(&commisionRateStr, "rate", "", "commission rate")
subCmdNewValidator.Flags().StringVar(&commisionMaxRateStr, "max-rate", "", "commision max rate")
subCmdNewValidator.Flags().StringVar(&commisionMaxChangeRateStr, "max-change-rate", "", "commission max change amount")
subCmdNewValidator.Flags().Float64Var(&minSelfDelegation, "min-self-delegation", 0.0, "minimal self delegation")
subCmdNewValidator.Flags().Var(&stakingAddress, "staking-addr", "validator's staking address")
subCmdNewValidator.Flags().StringVar(&stakingBlsPubKey, "pubkey", "","validator's public BLS key address")
subCmdNewValidator.Flags().StringVar(&stakingBlsPubKey, "pubkey", "", "validator's public BLS key address")
subCmdNewValidator.Flags().Float64Var(&stakingAmount, "amount", 0.0, "staking amount")
subCmdNewValidator.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
subCmdNewValidator.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
subCmdNewValidator.Flags().Var(&chainName, "chain-id", "what chain ID to target")
subCmdNewValidator.Flags().StringVar(&unlockP,
"passphrase", common.DefaultPassphrase,
@ -214,7 +217,7 @@ Create a new validator"
)
for _, flagName := range [...]string{"name", "identity", "website", "security-contact", "details", "rate", "max-rate",
"max-change-rate", "min-self-delegation","staking-addr", "pubkey", "amount", } {
"max-change-rate", "min-self-delegation", "staking-addr", "pubkey", "amount"} {
subCmdNewValidator.MarkFlagRequired(flagName)
}
@ -224,7 +227,7 @@ Create a new validator"
Long: `
Edit an existing validator"
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
networkHandler, err := handlerForShard(0, node)
if err != nil {
return err
@ -240,7 +243,7 @@ Edit an existing validator"
minSelfDel := minSelfDelegationBigInt.Mul(minSelfDelegationBigInt, big.NewInt(denominations.Nano))
return staking.DirectiveEditValidator, staking.EditValidator{
staking.Description {
staking.Description{
validatorName,
validatorIdentity,
validatorWebsite,
@ -267,16 +270,15 @@ Edit an existing validator"
},
}
subCmdEditValidator.Flags().StringVar(&validatorName, "name", "","validator's name")
subCmdEditValidator.Flags().StringVar(&validatorName, "name", "", "validator's name")
subCmdEditValidator.Flags().StringVar(&validatorIdentity, "identity", "", "validator's identity")
subCmdEditValidator.Flags().StringVar(&validatorWebsite, "website", "", "validator's website")
subCmdEditValidator.Flags().StringVar(&validatorSecurityContact, "security-contact", "","validator's security contact")
subCmdEditValidator.Flags().StringVar(&validatorSecurityContact, "security-contact", "", "validator's security contact")
subCmdEditValidator.Flags().StringVar(&validatorDetails, "details", "", "validator's details")
subCmdEditValidator.Flags().StringVar(&commisionRateStr, "rate", "","commission rate")
subCmdEditValidator.Flags().StringVar(&commisionRateStr, "rate", "", "commission rate")
subCmdEditValidator.Flags().Float64Var(&minSelfDelegation, "min-self-delegation", 0.0, "minimal self delegation")
subCmdEditValidator.Flags().Var(&stakingAddress, "staking-addr", "validator's staking address")
subCmdEditValidator.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
subCmdEditValidator.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
subCmdEditValidator.Flags().Var(&chainName, "chain-id", "what chain ID to target")
subCmdEditValidator.Flags().StringVar(&unlockP,
"passphrase", common.DefaultPassphrase,
@ -284,7 +286,7 @@ Edit an existing validator"
)
for _, flagName := range [...]string{"name", "identity", "website", "security-contact", "details", "rate",
"min-self-delegation","staking-addr", } {
"min-self-delegation", "staking-addr"} {
subCmdEditValidator.MarkFlagRequired(flagName)
}
@ -327,7 +329,7 @@ Delegating to a validator
subCmdDelegate.Flags().Var(&delegatorAddress, "delegator", "delegator's address")
subCmdDelegate.Flags().Var(&validatorAddress, "validator", "validator's address")
subCmdDelegate.Flags().Float64Var(&stakingAmount, "amount", 0.0, "staking amount")
subCmdDelegate.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
subCmdDelegate.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
subCmdDelegate.Flags().Var(&chainName, "chain-id", "what chain ID to target")
subCmdDelegate.Flags().StringVar(&unlockP,
"passphrase", common.DefaultPassphrase,
@ -344,7 +346,7 @@ Delegating to a validator
Long: `
Remove delegating to a validator
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
networkHandler, err := handlerForShard(0, node)
if err != nil {
return err
@ -377,7 +379,7 @@ Remove delegating to a validator
subCmdUnDelegate.Flags().Var(&delegatorAddress, "delegator", "delegator's address")
subCmdUnDelegate.Flags().Var(&validatorAddress, "validator", "source validator's address")
subCmdUnDelegate.Flags().Float64Var(&stakingAmount, "amount", 0.0, "staking amount")
subCmdUnDelegate.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
subCmdUnDelegate.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
subCmdUnDelegate.Flags().Var(&chainName, "chain-id", "what chain ID to target")
subCmdUnDelegate.Flags().StringVar(&unlockP,
"passphrase", common.DefaultPassphrase,
@ -429,7 +431,7 @@ Re-delegating to a validator
subCmdReDelegate.Flags().Float64Var(&stakingAmount, "amount", 0.0, "staking amount")
subCmdReDelegate.Flags().Var(&validatorSrcAddress, "src-validator", "source validator's address")
subCmdReDelegate.Flags().Var(&validatorDstAddress, "dest-validator", "destination validator's address")
subCmdReDelegate.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
subCmdReDelegate.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
subCmdReDelegate.Flags().Var(&chainName, "chain-id", "what chain ID to target")
subCmdReDelegate.Flags().StringVar(&unlockP,
"passphrase", common.DefaultPassphrase,

@ -25,7 +25,7 @@ var (
chainName = chainIDWrapper{chainID: &common.Chain.TestNet}
dryRun bool
unlockP string
gasPrice float64
gasPrice int64
)
func handlerForShard(senderShard uint32, node string) (*rpc.HTTPMessenger, error) {
@ -115,7 +115,7 @@ Create a transaction, sign it, and send off to the Harmony blockchain
cmdTransfer.Flags().Var(&toAddress, "to", "the destination one address")
cmdTransfer.Flags().BoolVar(&dryRun, "dry-run", false, "do not send signed transaction")
cmdTransfer.Flags().Float64Var(&amount, "amount", 0.0, "amount")
cmdTransfer.Flags().Float64Var(&gasPrice, "gas-price", 0.0, "gas price to pay")
cmdTransfer.Flags().Int64Var(&gasPrice, "gas-price", 1, "gas price to pay")
cmdTransfer.Flags().Uint32Var(&fromShardID, "from-shard", 0, "source shard id")
cmdTransfer.Flags().Uint32Var(&toShardID, "to-shard", 0, "target shard id")
cmdTransfer.Flags().Var(&chainName, "chain-id", "what chain ID to target")

@ -61,6 +61,7 @@ github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhY
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/gosigar v0.10.5/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs=
github.com/etcd-io/bbolt v1.3.2/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=

@ -166,13 +166,13 @@ func (C *Controller) setReceiver(receiver string) {
C.transactionForRPC.params["receiver"] = address.Parse(receiver)
}
func (C *Controller) setNewTransactionWithDataAndGas(i string, amount, gasPrice float64) {
func (C *Controller) setNewTransactionWithDataAndGas(i string, amount float64, gasPrice int64) {
if C.failure != nil {
return
}
amountBigInt := big.NewInt(int64(amount * denominations.Nano))
amt := amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano))
gPrice := big.NewInt(int64(gasPrice))
gPrice := big.NewInt(gasPrice)
gPrice = gPrice.Mul(gPrice, big.NewInt(denominations.Nano))
tx := NewTransaction(
@ -188,6 +188,7 @@ func (C *Controller) setNewTransactionWithDataAndGas(i string, amount, gasPrice
C.transactionForRPC.transaction = tx
}
// TransactionToJSON dumps JSON rep
func (C *Controller) TransactionToJSON(pretty bool) string {
r, _ := C.transactionForRPC.transaction.MarshalJSON()
if pretty {
@ -196,6 +197,7 @@ func (C *Controller) TransactionToJSON(pretty bool) string {
return string(r)
}
// RawTransaction dumps the signature as string
func (C *Controller) RawTransaction() string {
return *C.transactionForRPC.signature
}
@ -276,9 +278,12 @@ func (C *Controller) txConfirmation() {
}
}
// ExecuteTransaction is the single entrypoint to execute a transaction.
// Each step in transaction creation, execution probably includes a mutation
// Each becomes a no-op if failure occured in any previous step
func (C *Controller) ExecuteTransaction(
to, inputData string,
amount, gPrice float64,
amount float64, gPrice int64,
fromShard, toShard int,
) error {
// WARNING Order of execution matters

Loading…
Cancel
Save