Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
c2f6c681
Unverified
Commit
c2f6c681
authored
Jun 13, 2023
by
OptimismBot
Committed by
GitHub
Jun 13, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5781 from ethereum-optimism/op-bindings/better-error-handling
op-bindings: error handling
parents
538f569b
d4287042
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
registry.go
op-bindings/bindings/registry.go
+30
-0
No files found.
op-bindings/bindings/registry.go
View file @
c2f6c681
...
...
@@ -2,15 +2,20 @@ package bindings
import
(
"fmt"
"strings"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/common"
)
// layouts respresents the set of storage layouts. It is populated in an init function.
var
layouts
=
make
(
map
[
string
]
*
solc
.
StorageLayout
)
// deployedBytecodes represents the set of deployed bytecodes. It is populated
// in an init function.
var
deployedBytecodes
=
make
(
map
[
string
]
string
)
// GetStorageLayout returns the storage layout of a contract by name.
func
GetStorageLayout
(
name
string
)
(
*
solc
.
StorageLayout
,
error
)
{
layout
:=
layouts
[
name
]
if
layout
==
nil
{
...
...
@@ -19,11 +24,36 @@ func GetStorageLayout(name string) (*solc.StorageLayout, error) {
return
layout
,
nil
}
// GetDeployedBytecode returns the deployed bytecode of a contract by name.
func
GetDeployedBytecode
(
name
string
)
([]
byte
,
error
)
{
bc
:=
deployedBytecodes
[
name
]
if
bc
==
""
{
return
nil
,
fmt
.
Errorf
(
"%s: deployed bytecode not found"
,
name
)
}
if
!
isHex
(
bc
)
{
return
nil
,
fmt
.
Errorf
(
"%s: invalid deployed bytecode"
,
name
)
}
return
common
.
FromHex
(
bc
),
nil
}
// isHexCharacter returns bool of c being a valid hexadecimal.
func
isHexCharacter
(
c
byte
)
bool
{
return
(
'0'
<=
c
&&
c
<=
'9'
)
||
(
'a'
<=
c
&&
c
<=
'f'
)
||
(
'A'
<=
c
&&
c
<=
'F'
)
}
// isHex validates whether each byte is valid hexadecimal string.
func
isHex
(
str
string
)
bool
{
if
len
(
str
)
%
2
!=
0
{
return
false
}
str
=
strings
.
TrimPrefix
(
str
,
"0x"
)
for
_
,
c
:=
range
[]
byte
(
str
)
{
if
!
isHexCharacter
(
c
)
{
return
false
}
}
return
true
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment