MCPcopy Create free account
hub / github.com/CPChain/chain / GetRealContractAddress

Function GetRealContractAddress

core/vm/evm_proxy_helper.go:23–61  ·  view source on GitHub ↗

GetRealContractAddress get real logic contract address by proxy contract address

(evm *EVM, caller ContractRef, proxyContractAddress common.Address, gas uint64)

Source from the content-addressed store, hash-verified

21
22// GetRealContractAddress get real logic contract address by proxy contract address
23func GetRealContractAddress(evm *EVM, caller ContractRef, proxyContractAddress common.Address, gas uint64) common.Address {
24 if !configs.EnableProxyContract {
25 return proxyContractAddress
26 }
27
28 realAddress := proxyContractAddress
29
30 if dc := evm.chainConfig.Dpor; dc != nil {
31 if proxyRegister := dc.ProxyContractRegister; proxyRegister != emptyAddress {
32 // lookup in cache
33 realContractFromCache, gotIt := contractLookupCache.Get(proxyContractAddress)
34 if gotIt {
35 log.Debug("get real address from cache for", "proxyContractAddress", proxyContractAddress.Hex())
36 return realContractFromCache.(common.Address)
37 }
38
39 // setup param from #getContractInput(methodSignature,proxyAddress)
40 paramBytes := getContractInput(proxyContractAddress)
41 if ret, _, err := evm.StaticCall(caller, proxyRegister, paramBytes, gas); err == nil {
42 // get real contract address parse from ret
43 address := common.BytesToAddress(ret)
44 if address != emptyAddress {
45 log.Debug("GetRealContractAddress ", "hex(address)", common.Bytes2Hex(ret), "address", address.Hex())
46 }
47
48 if address != emptyAddress {
49 log.Debug("parseAddress ok", "realAddress", realAddress.Hex())
50 realAddress = address
51 contractLookupCache.Add(proxyContractAddress, realAddress, forceLookupTTL)
52 }
53 } else {
54 log.Warn("GetRealContractAddress", "err", err)
55 }
56 }
57 }
58
59 log.Debug("GetRealContractAddress", "realAddress", realAddress.Hex())
60 return realAddress
61}
62
63// invoke contract method in proxyContractRegister.sol#getRealContract
64func getContractInput(proxyContract common.Address) []byte {

Callers 3

CallMethod · 0.85
CallCodeMethod · 0.85
DelegateCallMethod · 0.85

Calls 6

getContractInputFunction · 0.85
DebugMethod · 0.80
StaticCallMethod · 0.80
GetMethod · 0.65
AddMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected