Skip to content

Commit

Permalink
Change the JSON representation of muxed ids to string (#3716)
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio authored Jun 23, 2021
1 parent 4149007 commit ccdcbcb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions protocols/horizon/effects/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ type Base struct {
PT string `json:"paging_token"`
Account string `json:"account"`
AccountMuxed string `json:"account_muxed,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"`
Type string `json:"type"`
TypeI int32 `json:"type_i"`
LedgerCloseTime time.Time `json:"created_at"`
Expand Down Expand Up @@ -385,7 +385,7 @@ type Trade struct {
Base
Seller string `json:"seller"`
SellerMuxed string `json:"seller_muxed,omitempty"`
SellerMuxedID uint64 `json:"seller_muxed_id,omitempty"`
SellerMuxedID uint64 `json:"seller_muxed_id,omitempty,string"`
OfferID int64 `json:"offer_id,string"`
SoldAmount string `json:"sold_amount"`
SoldAssetType string `json:"sold_asset_type"`
Expand Down
4 changes: 2 additions & 2 deletions protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ type Transaction struct {
LedgerCloseTime time.Time `json:"created_at"`
Account string `json:"source_account"`
AccountMuxed string `json:"account_muxed,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"`
AccountSequence string `json:"source_account_sequence"`
FeeAccount string `json:"fee_account"`
FeeAccountMuxed string `json:"fee_account_muxed,omitempty"`
FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty"`
FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty,string"`
FeeCharged int64 `json:"fee_charged,string"`
MaxFee int64 `json:"max_fee,string"`
OperationCount int32 `json:"operation_count"`
Expand Down
16 changes: 8 additions & 8 deletions protocols/horizon/operations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Base struct {
TransactionSuccessful bool `json:"transaction_successful"`
SourceAccount string `json:"source_account"`
SourceAccountMuxed string `json:"source_account_muxed,omitempty"`
SourceAccountMuxedID uint64 `json:"source_account_muxed_id,omitempty"`
SourceAccountMuxedID uint64 `json:"source_account_muxed_id,omitempty,string"`
Type string `json:"type"`
TypeI int32 `json:"type_i"`
LedgerCloseTime time.Time `json:"created_at"`
Expand Down Expand Up @@ -202,7 +202,7 @@ type ChangeTrust struct {
Trustee string `json:"trustee"`
Trustor string `json:"trustor"`
TrustorMuxed string `json:"trustor_muxed,omitempty"`
TrustorMuxedID uint64 `json:"trustor_muxed_id,omitempty"`
TrustorMuxedID uint64 `json:"trustor_muxed_id,omitempty,string"`
}

// Deprecated: use TrustlineFlagsUpdated instead.
Expand All @@ -213,7 +213,7 @@ type AllowTrust struct {
base.Asset
Trustee string `json:"trustee"`
TrusteeMuxed string `json:"trustee_muxed,omitempty"`
TrusteeMuxedID uint64 `json:"trustee_muxed_id,omitempty"`
TrusteeMuxedID uint64 `json:"trustee_muxed_id,omitempty,string"`
Trustor string `json:"trustor"`
Authorize bool `json:"authorize"`
AuthorizeToMaintainLiabilities bool `json:"authorize_to_maintain_liabilities"`
Expand All @@ -225,10 +225,10 @@ type AccountMerge struct {
Base
Account string `json:"account"`
AccountMuxed string `json:"account_muxed,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"`
Into string `json:"into"`
IntoMuxed string `json:"into_muxed,omitempty"`
IntoMuxedID uint64 `json:"into_muxed_id,omitempty"`
IntoMuxedID uint64 `json:"into_muxed_id,omitempty,string"`
}

// Inflation is the json resource representing a single operation whose type is
Expand All @@ -253,7 +253,7 @@ type ClaimClaimableBalance struct {
BalanceID string `json:"balance_id"`
Claimant string `json:"claimant"`
ClaimantMuxed string `json:"claimant_muxed,omitempty"`
ClaimantMuxedID uint64 `json:"claimant_muxed_id,omitempty"`
ClaimantMuxedID uint64 `json:"claimant_muxed_id,omitempty,string"`
}

// BeginSponsoringFutureReserves is the json resource representing a single operation whose type is
Expand All @@ -269,7 +269,7 @@ type EndSponsoringFutureReserves struct {
Base
BeginSponsor string `json:"begin_sponsor,omitempty"`
BeginSponsorMuxed string `json:"begin_sponsor_muxed,omitempty"`
BeginSponsorMuxedID uint64 `json:"begin_sponsor_muxed_id,omitempty"`
BeginSponsorMuxedID uint64 `json:"begin_sponsor_muxed_id,omitempty,string"`
}

// RevokeSponsorship is the json resource representing a single operation whose type is
Expand All @@ -294,7 +294,7 @@ type Clawback struct {
base.Asset
From string `json:"from"`
FromMuxed string `json:"from_muxed,omitempty"`
FromMuxedID uint64 `json:"from_muxed_id,omitempty"`
FromMuxedID uint64 `json:"from_muxed_id,omitempty,string"`
Amount string `json:"amount"`
}

Expand Down
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
**Upgrading to this version from <= v2.1.1 will trigger a state rebuild. During this process (which can take up to 20 minutes), Horizon will not ingest new ledgers.**

* Fix for Stellar-Core 17.1.0 bug that can potentially corrupt Captive-Core storage dir.
* All muxed ID fields are now represented as strings. This is to support JS that may not handle uint64 values in JSON responses properly.

## v2.5.0

Expand Down
8 changes: 4 additions & 4 deletions services/horizon/internal/resourceadapter/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,20 @@ func TestPopulateOperation_ClaimClaimableBalance_Muxed(t *testing.T) {
details := `{
"claimant": "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY",
"claimant_muxed": "MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26",
"claimant_muxed_id": 1234,
"claimant_muxed_id": "1234",
"balance_id": "abc",
"source_account_muxed": "MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26",
"source_account_muxed_id": 1234
"source_account_muxed_id": "1234"
}`

resp, err := getJSONResponse(xdr.OperationTypeClaimClaimableBalance, details)
tt.NoError(err)
tt.Equal("abc", resp["balance_id"])
tt.Equal("GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", resp["claimant"])
tt.Equal("MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26", resp["claimant_muxed"])
tt.Equal(1234, int(resp["claimant_muxed_id"].(float64)))
tt.Equal("1234", resp["claimant_muxed_id"])
tt.Equal("MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26", resp["source_account_muxed"])
tt.Equal(1234, int(resp["source_account_muxed_id"].(float64)))
tt.Equal("1234", resp["source_account_muxed_id"])
}

func TestPopulateOperation_BeginSponsoringFutureReserves(t *testing.T) {
Expand Down

0 comments on commit ccdcbcb

Please sign in to comment.