-
Notifications
You must be signed in to change notification settings - Fork 5
refactor: response fields #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f01b2e3
chore: replace `delegate` instances with `validator`
shahin-hq 8dcf701
chore: replace `delegate` instances with `validator`
shahin-hq 0d6b195
chore: replace `delegate` instances with `validator`
shahin-hq c17b91e
refactor: request/response fields
shahin-hq af1ecd3
refactor: request/response fields
shahin-hq bdaa73d
refactor: request/response fields
shahin-hq 0edebc9
wip
shahin-hq 6d76279
wip
shahin-hq 347332a
wip
shahin-hq e5d4b0a
wip
shahin-hq 438ce74
wip
shahin-hq bf3eabf
Merge branch 'chore/delegate-validator-migration' into refactor/reque…
shahin-hq 49864a7
Merge branch 'feat/mainsail' into refactor/request-response-fields
shahin-hq 285f804
Apply suggestions from code review
ItsANameToo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math/big" | ||
| "strings" | ||
| ) | ||
|
|
||
| // BigInt wraps *big.Int to (un)marshal the decimal-string format the API | ||
| // uses for wei-scale values (nonces, balances, fees, rewards), avoiding the | ||
| // range ceiling of uint64/uint32. | ||
| type BigInt struct { | ||
| *big.Int | ||
| } | ||
|
|
||
| // UnmarshalJSON and MarshalJSON intentionally use different receiver types | ||
| // (a lint tool may flag this). UnmarshalJSON must be a pointer receiver since | ||
| // it mutates b.Int; a value receiver would only update a local copy and the | ||
| // parsed value would be lost. MarshalJSON must stay a value receiver because | ||
| // BigInt is used as a map value elsewhere (e.g. NodeFeesResponse), and map | ||
| // values are not addressable in Go — a pointer receiver would fail to satisfy | ||
| // json.Marshaler there, silently falling back to *big.Int's default (bare, | ||
| // unquoted) JSON encoding instead of this type's quoted decimal-string format. | ||
|
ItsANameToo marked this conversation as resolved.
Outdated
|
||
| func (b *BigInt) UnmarshalJSON(data []byte) error { | ||
| s := strings.Trim(string(data), `"`) | ||
| if s == "" || s == "null" { | ||
| b.Int = big.NewInt(0) | ||
| return nil | ||
| } | ||
|
|
||
| i, ok := new(big.Int).SetString(s, 10) | ||
| if !ok { | ||
| return fmt.Errorf("client: invalid big integer %q", s) | ||
| } | ||
|
|
||
| b.Int = i | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (b BigInt) MarshalJSON() ([]byte, error) { | ||
| if b.Int == nil { | ||
| return []byte(`"0"`), nil | ||
| } | ||
|
|
||
| return []byte(`"` + b.Int.String() + `"`), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.