Skip to content
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
wants to merge 11 commits into
base: 5550/xdrill-transactions
Choose a base branch
from
47 changes: 47 additions & 0 deletions ingest/account_merge_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ingest
Copy link
Owner Author

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{}

Copy link
Owner Author

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


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
}
58 changes: 58 additions & 0 deletions ingest/allow_trust_details.go
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
}
18 changes: 18 additions & 0 deletions ingest/begin_sponsoring_future_reserve_details.go
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
}
18 changes: 18 additions & 0 deletions ingest/bump_sequence_details.go
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
}
85 changes: 85 additions & 0 deletions ingest/change_trust_details.go
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
}
46 changes: 46 additions & 0 deletions ingest/claim_claimable_balance_details.go
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
}
25 changes: 25 additions & 0 deletions ingest/clawback_claimable_balance_details.go
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
}
48 changes: 48 additions & 0 deletions ingest/clawback_details.go
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
}
36 changes: 36 additions & 0 deletions ingest/create_account_details.go
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
}
Loading
Loading