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
1f671532
Commit
1f671532
authored
Jun 30, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-bindings: fix canonicalize impl
parent
7ebc966a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
10 deletions
+13
-10
Makefile
op-bindings/Makefile
+2
-1
canonicalize.go
op-bindings/ast/canonicalize.go
+2
-7
canonicalize_test.go
op-bindings/ast/canonicalize_test.go
+1
-1
main.go
op-bindings/gen/main.go
+8
-1
No files found.
op-bindings/Makefile
View file @
1f671532
...
...
@@ -21,7 +21,8 @@ bindings-build:
-out
./bindings
\
-contracts
./artifacts.json
\
-source-maps
MIPS,PreimageOracle
\
-package
$(pkg)
-package
$(pkg)
\
-monorepo-base
$(
shell
dirname
$
(
realpath
.
))
mkdir
:
mkdir
-p
$(pkg)
...
...
op-bindings/ast/canonicalize.go
View file @
1f671532
...
...
@@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"golang.org/x/exp/slices"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
)
...
...
@@ -36,7 +34,7 @@ type typeRemapping struct {
// inefficiency comes from replaceType, which performs a linear
// search of all replacements when performing substring matches of
// composite types.
func
CanonicalizeASTIDs
(
in
*
solc
.
StorageLayout
)
*
solc
.
StorageLayout
{
func
CanonicalizeASTIDs
(
in
*
solc
.
StorageLayout
,
monorepoBase
string
)
*
solc
.
StorageLayout
{
lastId
:=
uint
(
1000
)
astIDRemappings
:=
make
(
map
[
uint
]
uint
)
typeRemappings
:=
make
(
map
[
string
]
string
)
...
...
@@ -92,10 +90,7 @@ func CanonicalizeASTIDs(in *solc.StorageLayout) *solc.StorageLayout {
// are used when there are 2 contracts imported with the same
// name
if
filepath
.
IsAbs
(
contract
)
{
elements
:=
strings
.
Split
(
contract
,
"/"
)
if
idx
:=
slices
.
Index
(
elements
,
"optimism"
);
idx
!=
-
1
{
contract
=
filepath
.
Join
(
elements
[
idx
+
1
:
]
...
)
}
contract
=
strings
.
TrimPrefix
(
strings
.
Replace
(
contract
,
monorepoBase
,
""
,
1
),
"/"
)
}
outLayout
.
Storage
=
append
(
outLayout
.
Storage
,
solc
.
StorageLayoutEntry
{
...
...
op-bindings/ast/canonicalize_test.go
View file @
1f671532
...
...
@@ -49,7 +49,7 @@ func TestCanonicalize(t *testing.T) {
// Run 100 times to make sure that we aren't relying
// on random map iteration order.
for
i
:=
0
;
i
<
100
;
i
++
{
require
.
Equal
(
t
,
testData
.
Out
,
CanonicalizeASTIDs
(
testData
.
In
))
require
.
Equal
(
t
,
testData
.
Out
,
CanonicalizeASTIDs
(
testData
.
In
,
""
))
}
})
}
...
...
op-bindings/gen/main.go
View file @
1f671532
...
...
@@ -22,6 +22,7 @@ type flags struct {
SourceMaps
string
OutDir
string
Package
string
MonorepoBase
string
}
type
data
struct
{
...
...
@@ -39,8 +40,14 @@ func main() {
flag
.
StringVar
(
&
f
.
Contracts
,
"contracts"
,
"artifacts.json"
,
"Path to file containing list of contracts to generate bindings for"
)
flag
.
StringVar
(
&
f
.
SourceMaps
,
"source-maps"
,
""
,
"Comma-separated list of contracts to generate source-maps for"
)
flag
.
StringVar
(
&
f
.
Package
,
"package"
,
"artifacts"
,
"Go package name"
)
flag
.
StringVar
(
&
f
.
MonorepoBase
,
"monorepo-base"
,
""
,
"Base of the monorepo"
)
flag
.
Parse
()
if
f
.
MonorepoBase
==
""
{
log
.
Fatal
(
"must provide -monorepo-base"
)
}
log
.
Printf
(
"Using monorepo base %s
\n
"
,
f
.
MonorepoBase
)
contractData
,
err
:=
os
.
ReadFile
(
f
.
Contracts
)
if
err
!=
nil
{
log
.
Fatal
(
"error reading contract list: %w
\n
"
,
err
)
...
...
@@ -147,7 +154,7 @@ func main() {
}
storage
:=
artifact
.
StorageLayout
canonicalStorage
:=
ast
.
CanonicalizeASTIDs
(
&
storage
)
canonicalStorage
:=
ast
.
CanonicalizeASTIDs
(
&
storage
,
f
.
MonorepoBase
)
ser
,
err
:=
json
.
Marshal
(
canonicalStorage
)
if
err
!=
nil
{
log
.
Fatalf
(
"error marshaling storage: %v
\n
"
,
err
)
...
...
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