-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fixed bid parsing for V1 #110
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,14 @@ | ||
{ | ||
"bonding_purse": "uref-b3c03358245a0d9514064b6d0c3dd90023d29a0fe137507d430a26990f5ce8e3-007", | ||
"staked_amount": "900000000000", | ||
"delegation_rate": 10, | ||
"delegators": [ | ||
{ | ||
"public_key": "02038f1f65c0297281a9eb5c83a525121715a8c71f1cdddabe70ae795dcd31b1ba92", | ||
"staked_amount": "555000000000", | ||
"bonding_purse": "uref-41059a3aa5c5759c7f5e3c826cb47e0b21257ac57ee63a4c00dc305133e55d64-007", | ||
"delegatee": "01d829cbfb66b2b11ef8d8feb6d3f2155789fc22f407bb57f89b05f6ba4b9ae070" | ||
} | ||
], | ||
"inactive": false | ||
} |
This file contains 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,20 @@ | ||
{ | ||
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61", | ||
"bonding_purse": "uref-fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa-007", | ||
"staked_amount": "900000000000", | ||
"delegation_rate": 0, | ||
"vesting_schedule": null, | ||
"delegators": [ | ||
{ | ||
"delegator_public_key": "014508a07aa941707f3eb2db94c8897a80b2c1197476b6de213ac273df7d86c4ff", | ||
"delegator": { | ||
"delegator_public_key": "01d829cbfb66b2b11ef8d8feb6d3f2155789fc22f407bb57f89b05f6ba4b9ae070", | ||
"staked_amount": "10", | ||
"bonding_purse": "uref-fbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb-007", | ||
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61", | ||
"vesting_schedule": null | ||
} | ||
} | ||
], | ||
"inactive": false | ||
} |
This file contains 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,41 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/make-software/casper-go-sdk/v2/types" | ||
) | ||
|
||
func Test_Bid_MarshalUnmarshal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fixturePath string | ||
}{ | ||
{ | ||
"Auction Bid V1", | ||
"../data/bid/auction_bid_example_v1.json", | ||
}, | ||
{ | ||
"Auction Bid V1", | ||
"../data/bid/auction_bid_example_v2.json", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
data, err := os.ReadFile(test.fixturePath) | ||
require.NoError(t, err) | ||
|
||
var bid types.Bid | ||
err = json.Unmarshal(data, &bid) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, bid.StakedAmount.String(), "900000000000") | ||
require.Equal(t, 1, len(bid.Delegators)) | ||
require.Equal(t, bid.Delegators[0].DelegatorPublicKey.ToHex(), "01d829cbfb66b2b11ef8d8feb6d3f2155789fc22f407bb57f89b05f6ba4b9ae070") | ||
}) | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -54,11 +54,12 @@ func (d *Delegators) UnmarshalJSON(data []byte) error { | |
} | ||
|
||
publicKeyAndDelegators := make([]struct { | ||
DelegatorPublicKey keypair.PublicKey `json:"delegator_public_key"` | ||
Delegator Delegator `json:"delegator"` | ||
DelegatorPublicKey *keypair.PublicKey `json:"delegator_public_key"` | ||
Delegator Delegator `json:"delegator"` | ||
}, 0) | ||
|
||
if err := json.Unmarshal(data, &publicKeyAndDelegators); err == nil && len(publicKeyAndDelegators) > 0 { | ||
err := json.Unmarshal(data, &publicKeyAndDelegators) | ||
if err == nil && len(publicKeyAndDelegators) > 0 && publicKeyAndDelegators[0].DelegatorPublicKey != nil { | ||
delegators := make(Delegators, 0, len(publicKeyAndDelegators)) | ||
for _, item := range publicKeyAndDelegators { | ||
delegators = append(delegators, item.Delegator) | ||
|
@@ -68,11 +69,16 @@ func (d *Delegators) UnmarshalJSON(data []byte) error { | |
return nil | ||
} | ||
|
||
delegators := make([]Delegator, 0) | ||
if err := json.Unmarshal(data, &publicKeyAndDelegators); err != nil { | ||
delegatorsV1 := make([]DelegatorV1, 0) | ||
if err := json.Unmarshal(data, &delegatorsV1); err != nil { | ||
return err | ||
} | ||
|
||
delegators := make(Delegators, 0, len(delegatorsV1)) | ||
for _, item := range delegatorsV1 { | ||
delegators = append(delegators, NewDelegatorFromDelegatorV1(item)) | ||
} | ||
|
||
*d = delegators | ||
return nil | ||
} | ||
|
@@ -91,6 +97,30 @@ type Delegator struct { | |
VestingSchedule *VestingSchedule `json:"vesting_schedule"` | ||
} | ||
|
||
// DelegatorV1 of version 1 which is associated with the given validator. | ||
type DelegatorV1 struct { | ||
// The purse that was used for delegating. | ||
BondingPurse key.URef `json:"bonding_purse"` | ||
// Amount of Casper token (in motes) delegated | ||
StakedAmount clvalue.UInt512 `json:"staked_amount"` | ||
// Public Key of the delegator | ||
Delegatee keypair.PublicKey `json:"delegatee"` | ||
// Public key of the validator | ||
ValidatorPublicKey keypair.PublicKey `json:"validator_public_key"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the schema please. I think the fields here are:
|
||
// Vesting schedule for a genesis validator. `None` if non-genesis validator. | ||
VestingSchedule *VestingSchedule `json:"vesting_schedule"` | ||
} | ||
|
||
func NewDelegatorFromDelegatorV1(v1 DelegatorV1) Delegator { | ||
return Delegator{ | ||
BondingPurse: v1.BondingPurse, | ||
StakedAmount: v1.StakedAmount, | ||
DelegatorPublicKey: v1.Delegatee, | ||
ValidatorPublicKey: v1.ValidatorPublicKey, | ||
VestingSchedule: v1.VestingSchedule, | ||
} | ||
} | ||
|
||
// Credit is a bridge record pointing to a new `ValidatorBid` after the public key was changed. | ||
type Credit struct { | ||
// The era id the credit was created. | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2?