當(dāng)提交智能合約部署后,會(huì)返回智能合約的地址。智能合約地址的生成邏輯在eth.api.go的submitTransaction函數(shù)中:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-543268.html
func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {
if err := b.SendTx(ctx, tx); err != nil { //提交交易
return common.Hash{}, err
}
if tx.To() == nil { //交易成功后,交易的目標(biāo)地址是空的話,說(shuō)明是智能合約部署
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
from, err := types.Sender(signer, tx) //獲取交易的發(fā)送地址
if err != nil {
return common.Hash{}, err
}
addr := crypto.CreateAddress(from, tx.Nonce()) //利用發(fā)送地址和nonce生成新的地址
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
} else {
log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
}
return tx.Hash(), nil
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-543268.html
到了這里,關(guān)于【區(qū)塊鏈 | 智能合約】Ethereum源代碼 - 智能合約地址生成算法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!