forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine code and fixed send tx sign for block signer.
- Loading branch information
Showing
4 changed files
with
78 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package contracts | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"math/big" | ||
) | ||
|
||
const ( | ||
HexSignMethod = "2fb1b25f" | ||
) | ||
|
||
// Send tx sign for block number to smart contract blockSigner. | ||
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block) { | ||
// Find active account. | ||
account := accounts.Account{} | ||
var wallet accounts.Wallet | ||
if wallets := manager.Wallets(); len(wallets) > 0 { | ||
wallet = wallets[0] | ||
if accts := wallets[0].Accounts(); len(accts) > 0 { | ||
account = accts[0] | ||
} | ||
} | ||
|
||
// Create and send tx to smart contract for sign validate block. | ||
blockHex := common.LeftPadBytes(block.Number().Bytes(), 32) | ||
data := common.Hex2Bytes(HexSignMethod) | ||
inputData := append(data, blockHex...) | ||
nonce := pool.State().GetNonce(account.Address) | ||
tx := types.NewTransaction(nonce, common.HexToAddress(common.BlockSigners), big.NewInt(0), 100000, big.NewInt(0), inputData) | ||
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId) | ||
if err != nil { | ||
log.Error("Fail to create tx sign", "error", err) | ||
return | ||
} | ||
|
||
// Add tx signed to local tx pool. | ||
pool.AddLocal(txSigned) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters