-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathcontract.go
68 lines (55 loc) · 2.13 KB
/
contract.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
64
65
66
67
68
package contracts
import (
"github.com/crytic/medusa/compilation/types"
)
// Contracts describes an array of contracts
type Contracts []*Contract
// MatchBytecode takes init and/or runtime bytecode and attempts to match it to a contract definition in the
// current list of contracts. It returns the contract definition if found. Otherwise, it returns nil.
func (c Contracts) MatchBytecode(initBytecode []byte, runtimeBytecode []byte) *Contract {
// Loop through all our contract definitions to find a match.
for i := 0; i < len(c); i++ {
// If we have a match, register the deployed contract.
if c[i].CompiledContract().IsMatch(initBytecode, runtimeBytecode) {
return c[i]
}
}
// If we found no definition, return nil.
return nil
}
// Contract describes a compiled smart contract.
type Contract struct {
// name represents the name of the contract.
name string
// sourcePath represents the key used to index the source file in the compilation it was derived from.
sourcePath string
// compiledContract describes the compiled contract data.
compiledContract *types.CompiledContract
// compilation describes the compilation which contains the compiledContract.
compilation *types.Compilation
}
// NewContract returns a new Contract instance with the provided information.
func NewContract(name string, sourcePath string, compiledContract *types.CompiledContract, compilation *types.Compilation) *Contract {
return &Contract{
name: name,
sourcePath: sourcePath,
compiledContract: compiledContract,
compilation: compilation,
}
}
// Name returns the name of the contract.
func (c *Contract) Name() string {
return c.name
}
// SourcePath returns the path of the source file containing the contract.
func (c *Contract) SourcePath() string {
return c.sourcePath
}
// CompiledContract returns the compiled contract information including source mappings, byte code, and ABI.
func (c *Contract) CompiledContract() *types.CompiledContract {
return c.compiledContract
}
// Compilation returns the compilation which contains the CompiledContract.
func (c *Contract) Compilation() *types.Compilation {
return c.compilation
}