forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
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
xdrill for operations #2
Open
chowbao
wants to merge
11
commits into
5550/xdrill-transactions
Choose a base branch
from
5551/xdrill-operations
base: 5550/xdrill-transactions
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,966
−0
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
314b605
xdrill for operations
chowbao e9d5511
Merge branch '5550/xdrill-transactions' into 5551/xdrill-operations
chowbao 3bc82f4
update tests
chowbao 3d7876c
Merge branch '5550/xdrill-transactions' into 5551/xdrill-operations
chowbao c68cd9a
updates from comments
chowbao 86d5d78
Add structs for each operation
chowbao b7c0737
Update marshalbase64
chowbao a3846f2
Fix typos
chowbao fc6b854
fix ci/cd
chowbao 875c995
fix tests
chowbao 5c68c65
Update hash.go
chowbao 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,47 @@ | ||
package ingest | ||
|
||
import "fmt" | ||
|
||
type AccountMergeDetail struct { | ||
Account string `json:"account"` | ||
AccountMuxed string `json:"account_muxed"` | ||
AccountMuxedID uint64 `json:"account_muxed_id"` | ||
Into string `json:"into"` | ||
IntoMuxed string `json:"into_muxed"` | ||
IntoMuxedID uint64 `json:"into_muxed_id"` | ||
} | ||
|
||
func (o *LedgerOperation) AccountMergeDetails() (AccountMergeDetail, error) { | ||
destinationAccount, ok := o.Operation.Body.GetDestination() | ||
if !ok { | ||
return AccountMergeDetail{}, fmt.Errorf("could not access Destination info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
accountMergeDetail := AccountMergeDetail{ | ||
Account: o.SourceAccount(), | ||
Into: destinationAccount.Address(), | ||
} | ||
|
||
var err error | ||
var accountMuxed string | ||
var accountMuxedID uint64 | ||
accountMuxed, accountMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR()) | ||
if err != nil { | ||
return AccountMergeDetail{}, err | ||
} | ||
|
||
accountMergeDetail.AccountMuxed = accountMuxed | ||
accountMergeDetail.AccountMuxedID = accountMuxedID | ||
|
||
var intoMuxed string | ||
var intoMuxedID uint64 | ||
intoMuxed, intoMuxedID, err = getMuxedAccountDetails(destinationAccount) | ||
if err != nil { | ||
return AccountMergeDetail{}, err | ||
} | ||
|
||
accountMergeDetail.IntoMuxed = intoMuxed | ||
accountMergeDetail.IntoMuxedID = intoMuxedID | ||
|
||
return accountMergeDetail, nil | ||
} |
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,58 @@ | ||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
type AllowTrustDetail struct { | ||
AssetCode string `json:"asset_code"` | ||
AssetIssuer string `json:"asset_issuer"` | ||
AssetType string `json:"asset_type"` | ||
Trustor string `json:"trustor"` | ||
Trustee string `json:"trustee"` | ||
TrusteeMuxed string `json:"trustee_muxed"` | ||
TrusteeMuxedID uint64 `json:"trustee_muxed_id"` | ||
Authorize bool `json:"authorize"` | ||
AuthorizeToMaintainLiabilities bool `json:"authorize_to_maintain_liabilities"` | ||
ClawbackEnabled bool `json:"clawback_enabled"` | ||
} | ||
|
||
func (o *LedgerOperation) AllowTrustDetails() (AllowTrustDetail, error) { | ||
op, ok := o.Operation.Body.GetAllowTrustOp() | ||
if !ok { | ||
return AllowTrustDetail{}, fmt.Errorf("could not access AllowTrust info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
allowTrustDetail := AllowTrustDetail{ | ||
Trustor: op.Trustor.Address(), | ||
Trustee: o.SourceAccount(), | ||
Authorize: xdr.TrustLineFlags(op.Authorize).IsAuthorized(), | ||
AuthorizeToMaintainLiabilities: xdr.TrustLineFlags(op.Authorize).IsAuthorizedToMaintainLiabilitiesFlag(), | ||
ClawbackEnabled: xdr.TrustLineFlags(op.Authorize).IsClawbackEnabledFlag(), | ||
} | ||
|
||
var err error | ||
var assetCode, assetIssuer, assetType string | ||
err = op.Asset.ToAsset(o.sourceAccountXDR().ToAccountId()).Extract(&assetType, &assetCode, &assetIssuer) | ||
if err != nil { | ||
return AllowTrustDetail{}, err | ||
} | ||
|
||
allowTrustDetail.AssetCode = assetCode | ||
allowTrustDetail.AssetIssuer = assetIssuer | ||
allowTrustDetail.AssetType = assetType | ||
|
||
var trusteeMuxed string | ||
var trusteeMuxedID uint64 | ||
trusteeMuxed, trusteeMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR()) | ||
if err != nil { | ||
return AllowTrustDetail{}, err | ||
} | ||
|
||
allowTrustDetail.TrusteeMuxed = trusteeMuxed | ||
allowTrustDetail.TrusteeMuxedID = trusteeMuxedID | ||
|
||
return allowTrustDetail, nil | ||
} |
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,18 @@ | ||
package ingest | ||
|
||
import "fmt" | ||
|
||
type BeginSponsoringFutureReservesDetail struct { | ||
SponsoredID string `json:"sponsored_id"` | ||
} | ||
|
||
func (o *LedgerOperation) BeginSponsoringFutureReservesDetails() (BeginSponsoringFutureReservesDetail, error) { | ||
op, ok := o.Operation.Body.GetBeginSponsoringFutureReservesOp() | ||
if !ok { | ||
return BeginSponsoringFutureReservesDetail{}, fmt.Errorf("could not access BeginSponsoringFutureReserves info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
return BeginSponsoringFutureReservesDetail{ | ||
SponsoredID: op.SponsoredId.Address(), | ||
}, nil | ||
} |
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,18 @@ | ||
package ingest | ||
|
||
import "fmt" | ||
|
||
type BumpSequenceDetails struct { | ||
BumpTo int64 `json:"bump_to"` | ||
} | ||
|
||
func (o *LedgerOperation) BumpSequenceDetails() (BumpSequenceDetails, error) { | ||
op, ok := o.Operation.Body.GetBumpSequenceOp() | ||
if !ok { | ||
return BumpSequenceDetails{}, fmt.Errorf("could not access BumpSequence info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
return BumpSequenceDetails{ | ||
BumpTo: int64(op.BumpTo), | ||
}, nil | ||
} |
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,85 @@ | ||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
type ChangeTrustDetail struct { | ||
AssetCode string `json:"asset_code"` | ||
AssetIssuer string `json:"asset_issuer"` | ||
AssetType string `json:"asset_type"` | ||
LiquidityPoolID string `json:"liquidity_pool_id"` | ||
Limit int64 `json:"limit"` | ||
Trustee string `json:"trustee"` | ||
Trustor string `json:"trustor"` | ||
TrustorMuxed string `json:"trustor_muxed"` | ||
TrustorMuxedID uint64 `json:"trustor_muxed_id"` | ||
} | ||
|
||
func (o *LedgerOperation) ChangeTrustDetails() (ChangeTrustDetail, error) { | ||
op, ok := o.Operation.Body.GetChangeTrustOp() | ||
if !ok { | ||
return ChangeTrustDetail{}, fmt.Errorf("could not access GetChangeTrust info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
var err error | ||
changeTrustDetail := ChangeTrustDetail{ | ||
Trustor: o.SourceAccount(), | ||
Limit: int64(op.Limit), | ||
} | ||
|
||
if op.Line.Type == xdr.AssetTypeAssetTypePoolShare { | ||
changeTrustDetail.AssetType, changeTrustDetail.LiquidityPoolID, err = getLiquidityPoolAssetDetails(*op.Line.LiquidityPool) | ||
if err != nil { | ||
return ChangeTrustDetail{}, err | ||
} | ||
} else { | ||
var assetCode, assetIssuer, assetType string | ||
err = op.Line.ToAsset().Extract(&assetType, &assetCode, &assetIssuer) | ||
if err != nil { | ||
return ChangeTrustDetail{}, err | ||
} | ||
|
||
changeTrustDetail.AssetCode = assetCode | ||
changeTrustDetail.AssetIssuer = assetIssuer | ||
changeTrustDetail.AssetType = assetType | ||
changeTrustDetail.Trustee = assetIssuer | ||
} | ||
|
||
var trustorMuxed string | ||
var trustorMuxedID uint64 | ||
trustorMuxed, trustorMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR()) | ||
if err != nil { | ||
return ChangeTrustDetail{}, err | ||
} | ||
|
||
changeTrustDetail.TrustorMuxed = trustorMuxed | ||
changeTrustDetail.TrustorMuxedID = trustorMuxedID | ||
|
||
return changeTrustDetail, nil | ||
} | ||
|
||
func getLiquidityPoolAssetDetails(lpp xdr.LiquidityPoolParameters) (string, string, error) { | ||
if lpp.Type != xdr.LiquidityPoolTypeLiquidityPoolConstantProduct { | ||
return "", "", fmt.Errorf("unknown liquidity pool type %d", lpp.Type) | ||
} | ||
|
||
cp := lpp.ConstantProduct | ||
|
||
var err error | ||
var poolID xdr.PoolId | ||
var poolIDString string | ||
poolID, err = xdr.NewPoolId(cp.AssetA, cp.AssetB, cp.Fee) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
poolIDString, err = PoolIDToString(poolID) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
return "liquidity_pool_shares", poolIDString, nil | ||
} |
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,46 @@ | ||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
type ClaimClaimableBalanceDetail struct { | ||
BalanceID string `json:"balance_id"` | ||
Claimant string `json:"claimant"` | ||
ClaimantMuxed string `json:"claimant_muxed"` | ||
ClaimantMuxedID uint64 `json:"claimant_muxed_id"` | ||
} | ||
|
||
func (o *LedgerOperation) ClaimClaimableBalanceDetails() (ClaimClaimableBalanceDetail, error) { | ||
op, ok := o.Operation.Body.GetClaimClaimableBalanceOp() | ||
if !ok { | ||
return ClaimClaimableBalanceDetail{}, fmt.Errorf("could not access ClaimClaimableBalance info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
claimClaimableBalanceDetail := ClaimClaimableBalanceDetail{ | ||
Claimant: o.SourceAccount(), | ||
} | ||
|
||
var err error | ||
var balanceID string | ||
balanceID, err = xdr.MarshalBase64(op.BalanceId) | ||
if err != nil { | ||
return ClaimClaimableBalanceDetail{}, err | ||
} | ||
|
||
claimClaimableBalanceDetail.BalanceID = balanceID | ||
|
||
var claimantMuxed string | ||
var claimantMuxedID uint64 | ||
claimantMuxed, claimantMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR()) | ||
if err != nil { | ||
return ClaimClaimableBalanceDetail{}, err | ||
} | ||
|
||
claimClaimableBalanceDetail.ClaimantMuxed = claimantMuxed | ||
claimClaimableBalanceDetail.ClaimantMuxedID = claimantMuxedID | ||
|
||
return claimClaimableBalanceDetail, nil | ||
} |
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,25 @@ | ||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
type ClawbackClaimableBalanceDetail struct { | ||
BalanceID string `json:"balance_id"` | ||
} | ||
|
||
func (o *LedgerOperation) ClawbackClaimableBalanceDetails() (ClawbackClaimableBalanceDetail, error) { | ||
op, ok := o.Operation.Body.GetClawbackClaimableBalanceOp() | ||
if !ok { | ||
return ClawbackClaimableBalanceDetail{}, fmt.Errorf("could not access ClawbackClaimableBalance info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
balanceID, err := xdr.MarshalBase64(op.BalanceId) | ||
if err != nil { | ||
return ClawbackClaimableBalanceDetail{}, err | ||
} | ||
|
||
return ClawbackClaimableBalanceDetail{BalanceID: balanceID}, nil | ||
} |
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,48 @@ | ||
package ingest | ||
|
||
import "fmt" | ||
|
||
type ClawbackDetail struct { | ||
AssetCode string `json:"asset_code"` | ||
AssetIssuer string `json:"asset_issuer"` | ||
AssetType string `json:"asset_type"` | ||
From string `json:"from"` | ||
FromMuxed string `json:"from_muxed"` | ||
FromMuxedID uint64 `json:"from_muxed_id"` | ||
Amount int64 `json:"amount"` | ||
} | ||
|
||
func (o *LedgerOperation) ClawbackDetails() (ClawbackDetail, error) { | ||
op, ok := o.Operation.Body.GetClawbackOp() | ||
if !ok { | ||
return ClawbackDetail{}, fmt.Errorf("could not access Clawback info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
clawbackDetail := ClawbackDetail{ | ||
Amount: int64(op.Amount), | ||
From: op.From.Address(), | ||
} | ||
|
||
var err error | ||
var assetCode, assetIssuer, assetType string | ||
err = op.Asset.Extract(&assetType, &assetCode, &assetIssuer) | ||
if err != nil { | ||
return ClawbackDetail{}, err | ||
} | ||
|
||
clawbackDetail.AssetCode = assetCode | ||
clawbackDetail.AssetIssuer = assetIssuer | ||
clawbackDetail.AssetType = assetType | ||
|
||
var fromMuxed string | ||
var fromMuxedID uint64 | ||
fromMuxed, fromMuxedID, err = getMuxedAccountDetails(op.From) | ||
if err != nil { | ||
return ClawbackDetail{}, err | ||
} | ||
|
||
clawbackDetail.FromMuxed = fromMuxed | ||
clawbackDetail.FromMuxedID = fromMuxedID | ||
|
||
return clawbackDetail, nil | ||
} |
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,36 @@ | ||
package ingest | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type CreateAccountDetail struct { | ||
Account string `json:"account"` | ||
StartingBalance int64 `json:"starting_balance"` | ||
Funder string `json:"funder"` | ||
FunderMuxed string `json:"funder_muxed"` | ||
FunderMuxedID uint64 `json:"funder_muxed_id"` | ||
} | ||
|
||
func (o *LedgerOperation) CreateAccountDetails() (CreateAccountDetail, error) { | ||
op, ok := o.Operation.Body.GetCreateAccountOp() | ||
if !ok { | ||
return CreateAccountDetail{}, fmt.Errorf("could not access CreateAccount info for this operation (index %d)", o.OperationIndex) | ||
} | ||
|
||
createAccountDetail := CreateAccountDetail{ | ||
Account: op.Destination.Address(), | ||
StartingBalance: int64(op.StartingBalance), | ||
Funder: o.SourceAccount(), | ||
} | ||
|
||
funderMuxed, funderMuxedID, err := getMuxedAccountDetails(o.sourceAccountXDR()) | ||
if err != nil { | ||
return CreateAccountDetail{}, err | ||
} | ||
|
||
createAccountDetail.FunderMuxed = funderMuxed | ||
createAccountDetail.FunderMuxedID = funderMuxedID | ||
|
||
return createAccountDetail, nil | ||
} |
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.
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.
Similarly to #3 (comment)
OperationDetails has been updated to structs to preserve strict typing for data instead of the the previous map[string]string/interface{}
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.
Oh also if anyone has better suggestions for organizing and what dir to put these files in I'm happy to update. One issue is that golang doesn't let you put these in a different directory and still have it as part of the same package (only files in the same dir can go in the same package) but if I separate these functions out to their own package I create a circular dependency with go/ingest