go-ethereum/contracts/blocksigner/blocksigner.go
2018-10-27 17:52:28 +05:30

42 lines
No EOL
1.2 KiB
Go

package blocksigner
import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
"math/big"
)
type BlockSigner struct {
*contract.BlockSignerSession
contractBackend bind.ContractBackend
}
func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*BlockSigner, error) {
blockSigner, err := contract.NewBlockSigner(contractAddr, contractBackend)
if err != nil {
return nil, err
}
return &BlockSigner{
&contract.BlockSignerSession{
Contract: blockSigner,
TransactOpts: *transactOpts,
},
contractBackend,
}, nil
}
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) {
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber)
if err != nil {
return blockSignerAddr, nil, err
}
blockSigner, err := NewBlockSigner(transactOpts, blockSignerAddr, contractBackend)
if err != nil {
return blockSignerAddr, nil, err
}
return blockSignerAddr, blockSigner, nil
}