github.com/Night-mk/quorum@v21.1.0+incompatible/extension/contract_facade.go (about)

     1  package extension
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/ethereum/go-ethereum/accounts/abi/bind"
     7  	"github.com/ethereum/go-ethereum/common"
     8  	"github.com/ethereum/go-ethereum/core/types"
     9  	"github.com/ethereum/go-ethereum/ethclient"
    10  	"github.com/ethereum/go-ethereum/extension/extensionContracts"
    11  )
    12  
    13  type ManagementContractFacade interface {
    14  	Transactor(managementAddress common.Address) (*extensionContracts.ContractExtenderTransactor, error)
    15  	Caller(managementAddress common.Address) (*extensionContracts.ContractExtenderCaller, error)
    16  	Deploy(args *bind.TransactOpts, toExtend common.Address, recipientAddress common.Address, recipientHash string) (*types.Transaction, error)
    17  
    18  	GetAllVoters(addressToVoteOn common.Address) ([]common.Address, error)
    19  }
    20  
    21  type EthclientManagementContractFacade struct {
    22  	client *ethclient.Client
    23  }
    24  
    25  func NewManagementContractFacade(client *ethclient.Client) ManagementContractFacade {
    26  	return EthclientManagementContractFacade{client: client}
    27  }
    28  
    29  func (facade EthclientManagementContractFacade) Transactor(managementAddress common.Address) (*extensionContracts.ContractExtenderTransactor, error) {
    30  	return extensionContracts.NewContractExtenderTransactor(managementAddress, facade.client)
    31  }
    32  
    33  func (facade EthclientManagementContractFacade) Caller(managementAddress common.Address) (*extensionContracts.ContractExtenderCaller, error) {
    34  	return extensionContracts.NewContractExtenderCaller(managementAddress, facade.client)
    35  }
    36  
    37  func (facade EthclientManagementContractFacade) Deploy(args *bind.TransactOpts, toExtend common.Address, recipientAddress common.Address, recipientHash string) (*types.Transaction, error) {
    38  	_, tx, _, err := extensionContracts.DeployContractExtender(args, facade.client, toExtend, recipientAddress, recipientHash)
    39  	return tx, err
    40  }
    41  
    42  func (facade EthclientManagementContractFacade) GetAllVoters(addressToVoteOn common.Address) ([]common.Address, error) {
    43  	caller, err := facade.Caller(addressToVoteOn)
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	numberOfVoters, err := caller.TotalNumberOfVoters(nil)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	var i int64
    52  	var voters []common.Address
    53  	for i = 0; i < numberOfVoters.Int64(); i++ {
    54  		voter, err := caller.WalletAddressesToVote(nil, big.NewInt(i))
    55  		if err != nil {
    56  			return nil, err
    57  		}
    58  		voters = append(voters, voter)
    59  	}
    60  	return voters, nil
    61  }