Eth源码阅读(转账)

作者: 坠叶飘香 | 来源:发表于2018-09-18 16:00 被阅读0次

1.结构体

SendTxArgs


SendTxArgs

TxPool


TxPool

2.SendTransaction

go-ethereum/internal/ethapi/api.go


SendTransaction
2.1 signTransaction

go-ethereum/internal/ethapi/api.go


signTransaction
setDefaults
2.1.1 toTransaction

go-ethereum/internal/ethapi/api.go


toTransaction
2.1.1.1 newTransaction

go-ethereum/core/types/transaction.go


newTransaction
2.1.2 SignTxWithPassphrase

最终调用go-ethereum/core/types/transaction.go的WithSignature


WithSignature
2.2 submitTransaction

go-ethereum/internal/ethapi/api.go


submitTransaction
2.2.1 SendTx

最终会执行ethereum/go-ethereum/core/tx_pool.go的addTx


addTx
2.2.1.1 add

go-ethereum/core/tx_pool.go
(1)如果交易已经存在,直接返回


判断交易是否已经存在

(2)validateTx


校验交易
校验交易
(3)如果pool.all的size达到上限,则需要根据tx的gasPrice来决定是否能够放入pool
在pool.all的size达到上限时的处理

(4)如果已经有相同nonce的tx,则需要将old tx替换成new tx,发送NewTxsEvent事件


tx替换
(5)如果不存在相同nonce,则放入pool
放入pool

相关文章

网友评论

    本文标题:Eth源码阅读(转账)

    本文链接:https://www.haomeiwen.com/subject/alspnftx.html