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
2e574728
Commit
2e574728
authored
Nov 14, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct `Deployment` type
Add custom `Deployment` unmarshaller
parent
2673d26b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
types.go
op-bindings/hardhat/types.go
+57
-1
No files found.
op-bindings/hardhat/types.go
View file @
2e574728
...
...
@@ -2,6 +2,7 @@ package hardhat
import
(
"encoding/json"
"strings"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/accounts/abi"
...
...
@@ -14,7 +15,7 @@ type Deployment struct {
Name
string
Abi
abi
.
ABI
`json:"abi"`
Address
common
.
Address
`json:"address"`
Args
[]
any
`json:"args
"`
Args
[]
interface
{}
`json:"-
"`
Bytecode
hexutil
.
Bytes
`json:"bytecode"`
DeployedBytecode
hexutil
.
Bytes
`json:"deployedBytecode"`
Devdoc
json
.
RawMessage
`json:"devdoc"`
...
...
@@ -26,6 +27,61 @@ type Deployment struct {
Userdoc
json
.
RawMessage
`json:"userdoc"`
}
// UnmarshalJSON is a custom unmarshaler for Deployment, handling the Args field. This changed recently
// when `foundry` migrated to `alloy` types, and now the Args field within the contract artifact has
// a different serialization format.
//
// This custom unmarshaller should be removed when this is fixed upstream.
//
// Old Example:
// ```
// "args": [
//
// "0xCE9FeE676767A25feb9722986148Fcd87085a14e",
// "OVM_L1CrossDomainMessenger"
//
// ],
// ```
//
// New Example:
// ```
// "args": "[\"0x45ce2021212883d655348778aC99707d63D49aBc\",\"\\OVM_L1CrossDomainMessenger\\\"]"
// ```
func
(
d
*
Deployment
)
UnmarshalJSON
(
data
[]
byte
)
error
{
// Create a type alias to prevent recursion
type
DeploymentAlias
Deployment
// Unmarshal all fields except for `Args`
var
alias
DeploymentAlias
if
err
:=
json
.
Unmarshal
(
data
,
&
alias
);
err
!=
nil
{
return
err
}
// Unmarshal `Args` manually.
tmp
:=
struct
{
Args
json
.
RawMessage
`json:"args"`
}{}
if
err
:=
json
.
Unmarshal
(
data
,
&
tmp
);
err
!=
nil
{
return
err
}
// Strip the `args` string of escapes and quotes.
stripped
:=
strings
.
ReplaceAll
(
strings
.
Trim
(
string
(
tmp
.
Args
),
"
\"
"
),
"
\\
"
,
""
)
// Unmarshal the stripped version of the `args` field.
var
args
[]
interface
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
stripped
),
&
args
);
err
!=
nil
{
return
err
}
// Set the `Args` field in the `Deployment` to the correctly unmarshaled value
alias
.
Args
=
args
// Assign the unmarshaled alias back to the original struct
*
d
=
Deployment
(
alias
)
return
nil
}
// Receipt represents the receipt held in a hardhat-deploy
// artifact file
type
Receipt
struct
{
...
...
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