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.
81 lines
2.6 KiB
81 lines
2.6 KiB
8 months ago
|
package wiki
|
||
4 years ago
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
8 months ago
|
"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"
|
||
4 years ago
|
)
|
||
|
|
||
|
// SendTx ...
|
||
8 months ago
|
func (wiki *Woop) SendTx(ctx context.Context, signedTx *types.Transaction) error {
|
||
|
tx, _, _, _ := rawdb.ReadTransaction(wiki.chainDb, signedTx.Hash())
|
||
4 years ago
|
if tx == nil {
|
||
8 months ago
|
return wiki.NodeAPI.AddPendingTransaction(signedTx)
|
||
4 years ago
|
}
|
||
|
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
|
||
8 months ago
|
func (wiki *Woop) ResendCx(ctx context.Context, txID common.Hash) (uint64, bool) {
|
||
|
blockHash, blockNum, index := wiki.BlockChain.ReadTxLookupEntry(txID)
|
||
4 years ago
|
if blockHash == (common.Hash{}) {
|
||
|
return 0, false
|
||
|
}
|
||
|
|
||
8 months ago
|
blk := wiki.BlockChain.GetBlockByHash(blockHash)
|
||
4 years ago
|
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
|
||
|
}
|
||
3 years ago
|
entry := core.CxEntry{BlockHash: blockHash, ToShardID: tx.ToShardID()}
|
||
8 months ago
|
success := wiki.CxPool.Add(entry)
|
||
4 years ago
|
return blockNum, success
|
||
|
}
|
||
|
|
||
|
// GetReceipts ...
|
||
8 months ago
|
func (wiki *Woop) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||
|
return wiki.BlockChain.GetReceiptsByHash(hash), nil
|
||
4 years ago
|
}
|
||
|
|
||
|
// GetTransactionsHistory returns list of transactions hashes of address.
|
||
8 months ago
|
func (wiki *Woop) GetTransactionsHistory(address, txType, order string) ([]common.Hash, error) {
|
||
|
return wiki.NodeAPI.GetTransactionsHistory(address, txType, order)
|
||
4 years ago
|
}
|
||
|
|
||
|
// GetAccountNonce returns the nonce value of the given address for the given block number
|
||
8 months ago
|
func (wiki *Woop) GetAccountNonce(
|
||
4 years ago
|
ctx context.Context, address common.Address, blockNum rpc.BlockNumber) (uint64, error) {
|
||
8 months ago
|
state, _, err := wiki.StateAndHeaderByNumber(ctx, blockNum)
|
||
4 years ago
|
if state == nil || err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
return state.GetNonce(address), state.Error()
|
||
|
}
|
||
|
|
||
|
// GetTransactionsCount returns the number of regular transactions of address.
|
||
8 months ago
|
func (wiki *Woop) GetTransactionsCount(address, txType string) (uint64, error) {
|
||
|
return wiki.NodeAPI.GetTransactionsCount(address, txType)
|
||
4 years ago
|
}
|
||
|
|
||
|
// GetCurrentTransactionErrorSink ..
|
||
8 months ago
|
func (wiki *Woop) GetCurrentTransactionErrorSink() types.TransactionErrorReports {
|
||
|
return wiki.NodeAPI.ReportPlainErrorSink()
|
||
4 years ago
|
}
|