The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/wiki/transaction.go

80 lines
2.6 KiB

package wiki
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/woop-chain/woop/core"
"github.com/woop-chain/woop/core/rawdb"
"github.com/woop-chain/woop/core/types"
"github.com/woop-chain/woop/eth/rpc"
)
// SendTx ...
func (wiki *Woop) SendTx(ctx context.Context, signedTx *types.Transaction) error {
tx, _, _, _ := rawdb.ReadTransaction(wiki.chainDb, signedTx.Hash())
if tx == nil {
return wiki.NodeAPI.AddPendingTransaction(signedTx)
}
return ErrFinalizedTransaction
}
// ResendCx retrieve blockHash from txID and add blockHash to CxPool for resending
// Note that cross shard txn is only for regular txns, not for staking txns, so the input txn hash
// is expected to be regular txn hash
func (wiki *Woop) ResendCx(ctx context.Context, txID common.Hash) (uint64, bool) {
blockHash, blockNum, index := wiki.BlockChain.ReadTxLookupEntry(txID)
if blockHash == (common.Hash{}) {
return 0, false
}
blk := wiki.BlockChain.GetBlockByHash(blockHash)
if blk == nil {
return 0, false
}
txs := blk.Transactions()
// a valid index is from 0 to len-1
if int(index) > len(txs)-1 {
return 0, false
}
tx := txs[int(index)]
// check whether it is a valid cross shard tx
if tx.ShardID() == tx.ToShardID() || blk.Header().ShardID() != tx.ShardID() {
return 0, false
}
entry := core.CxEntry{BlockHash: blockHash, ToShardID: tx.ToShardID()}
success := wiki.CxPool.Add(entry)
return blockNum, success
}
// GetReceipts ...
func (wiki *Woop) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
return wiki.BlockChain.GetReceiptsByHash(hash), nil
}
// GetTransactionsHistory returns list of transactions hashes of address.
func (wiki *Woop) GetTransactionsHistory(address, txType, order string) ([]common.Hash, error) {
return wiki.NodeAPI.GetTransactionsHistory(address, txType, order)
}
// GetAccountNonce returns the nonce value of the given address for the given block number
func (wiki *Woop) GetAccountNonce(
ctx context.Context, address common.Address, blockNum rpc.BlockNumber) (uint64, error) {
state, _, err := wiki.StateAndHeaderByNumber(ctx, blockNum)
if state == nil || err != nil {
return 0, err
}
return state.GetNonce(address), state.Error()
}
// GetTransactionsCount returns the number of regular transactions of address.
func (wiki *Woop) GetTransactionsCount(address, txType string) (uint64, error) {
return wiki.NodeAPI.GetTransactionsCount(address, txType)
}
// GetCurrentTransactionErrorSink ..
func (wiki *Woop) GetCurrentTransactionErrorSink() types.TransactionErrorReports {
return wiki.NodeAPI.ReportPlainErrorSink()
}