forked from celo-org/celo-blockchain
/
dynamic_params.go
63 lines (53 loc) · 2.41 KB
/
dynamic_params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package vm
import (
"strings"
"github.com/conclave-dev/celo-blockchain/accounts/abi"
"github.com/conclave-dev/celo-blockchain/common"
"github.com/conclave-dev/celo-blockchain/contract_comm/errors"
"github.com/conclave-dev/celo-blockchain/params"
)
const (
// This is taken from celo-monorepo/packages/protocol/build/<env>/contracts/Registry.json
getAddressForABI = `[{"constant": true,
"inputs": [
{
"name": "identifier",
"type": "bytes32"
}
],
"name": "getAddressFor",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}]`
)
var getAddressForFuncABI, _ = abi.JSON(strings.NewReader(getAddressForABI))
// TODO(kevjue) - Re-Enable caching of the retrieved registered address
// See this commit for the removed code for caching: https://github.com/celo-org/geth/commit/43a275273c480d307a3d2b3c55ca3b3ee31ec7dd.
func GetRegisteredAddressWithEvm(registryId [32]byte, evm *EVM) (*common.Address, error) {
evm.DontMeterGas = true
defer func() { evm.DontMeterGas = false }()
// TODO(mcortesi) remove registrypoxy deployed at genesis
if evm.GetStateDB().GetCodeSize(params.RegistrySmartContractAddress) == 0 {
return nil, errors.ErrRegistryContractNotDeployed
}
var contractAddress common.Address
_, err := evm.StaticCallFromSystem(params.RegistrySmartContractAddress, getAddressForFuncABI, "getAddressFor", []interface{}{registryId}, &contractAddress, params.MaxGasForGetAddressFor)
// TODO (mcortesi) Remove ErrEmptyArguments check after we change Proxy to fail on unset impl
// TODO(asa): Why was this change necessary?
if err == abi.ErrEmptyArguments || err == errExecutionReverted {
return nil, errors.ErrRegistryContractNotDeployed
} else if err != nil {
return nil, err
}
if contractAddress == common.ZeroAddress {
return nil, errors.ErrSmartContractNotDeployed
}
return &contractAddress, nil
}