Fetch multiple nodes from contract (#1430)

This commit is contained in:
Andrea Maria Piana 2019-03-29 18:49:01 +01:00 committed by GitHub
parent 8baae97e2e
commit f5875d62c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -242,7 +242,7 @@ func (b *StatusBackend) CallRPC(inputJSON string) (string, error) {
return client.CallRaw(inputJSON), nil return client.CallRaw(inputJSON), nil
} }
// GetNodesFromContract returns a list of mailservers // GetNodesFromContract returns a list of nodes from the contract
func (b *StatusBackend) GetNodesFromContract(rpcEndpoint string, contractAddress string) ([]string, error) { func (b *StatusBackend) GetNodesFromContract(rpcEndpoint string, contractAddress string) ([]string, error) {
var response []string var response []string
@ -259,12 +259,20 @@ func (b *StatusBackend) GetNodesFromContract(rpcEndpoint string, contractAddress
return response, err return response, err
} }
node, err := contract.Nodes(nil, big.NewInt(0)) nodeCount, err := contract.NodeCount(nil)
if err != nil { if err != nil {
return response, err return response, err
} }
response = append(response, node) one := big.NewInt(1)
for i := big.NewInt(0); i.Cmp(nodeCount) < 0; i.Add(i, one) {
node, err := contract.Nodes(nil, i)
if err != nil {
return response, err
}
response = append(response, node)
}
return response, nil return response, nil
} }

View File

@ -0,0 +1,6 @@
### Mailserver registry
The code for the contract interface used is at https://github.com/status-im/network-incentivisation/blob/master/contracts/Nodes.sol
and has been generated with abigen.
`abigen --sol contracts/Nodes.sol --pkg registry`