Merge pull request #1672 from rlan35/staking_specs
Add staking transaction struct and handler logicpull/1674/head
commit
f91c013ed2
@ -0,0 +1,33 @@ |
||||
package types |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/harmony-one/bls/ffi/go/bls" |
||||
"github.com/harmony-one/harmony/internal/common" |
||||
) |
||||
|
||||
// StakingMessage must fulfill these interfaces
|
||||
type StakingMessage interface { |
||||
// Type returns a human-readable string for the type of the staking message
|
||||
Type() string |
||||
|
||||
// Signer returns the ECDSA address who must sign the outer transaction
|
||||
Signer() common.Address |
||||
} |
||||
|
||||
// MsgCreateValidator - struct for creating a new validator
|
||||
type MsgCreateValidator struct { |
||||
Description Description `json:"description" yaml:"description"` |
||||
Commission CommissionRates `json:"commission" yaml:"commission"` |
||||
MinSelfDelegation big.Int `json:"min_self_delegation" yaml:"min_self_delegation"` |
||||
Address common.Address `json:"validator_address" yaml:"validator_address"` |
||||
ValidatingPubKey bls.PublicKey `json:"validating_pub_key" yaml:"validating_pub_key"` |
||||
Amount big.Int `json:"amount" yaml:"amount"` |
||||
} |
||||
|
||||
// Type ...
|
||||
func (msg MsgCreateValidator) Type() string { return "create_validator" } |
||||
|
||||
// Signer ...
|
||||
func (msg MsgCreateValidator) Signer() common.Address { return msg.Address } |
@ -0,0 +1,39 @@ |
||||
package types |
||||
|
||||
import ( |
||||
"bytes" |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/harmony-one/harmony/crypto/hash" |
||||
) |
||||
|
||||
// StakingTransaction struct.
|
||||
type StakingTransaction struct { |
||||
AccountNonce uint64 `json:"nonce" gencodec:"required"` |
||||
Price *big.Int `json:"gasPrice" gencodec:"required"` |
||||
GasLimit uint64 `json:"gas" gencodec:"required"` |
||||
Msg StakingMessage `json:"msg" gencodec:"required"` |
||||
|
||||
// Signature values
|
||||
V *big.Int `json:"v" gencodec:"required"` |
||||
R *big.Int `json:"r" gencodec:"required"` |
||||
S *big.Int `json:"s" gencodec:"required"` |
||||
|
||||
// This is only used when marshaling to JSON.
|
||||
hash *common.Hash `json:"hash" rlp:"-"` |
||||
} |
||||
|
||||
// StakingTransactions is a Transaction slice type for basic sorting.
|
||||
type StakingTransactions []*StakingTransaction |
||||
|
||||
// Hash hashes the RLP encoding of tx.
|
||||
// It uniquely identifies the transaction.
|
||||
func (tx *StakingTransaction) Hash() common.Hash { |
||||
emptyHash := common.Hash{} |
||||
if bytes.Compare(tx.hash[:], emptyHash[:]) == 0 { |
||||
h := hash.FromRLP(tx) |
||||
tx.hash = &h |
||||
} |
||||
return *tx.hash |
||||
} |
Loading…
Reference in new issue