Skip to content

Commit 34319a1

Browse files
committed
feat: enhance XRP and Stellar indexers
- Added Conflux mainnet and testnet configurations to the indexer. - Updated XRP indexer to handle new transaction types including clawback and claimable balance operations. - Enhanced Stellar indexer to support claimable balance operations and improved transaction metadata handling. - Removed outdated test files for Stellar and XRP indexers.
1 parent 7ca0f51 commit 34319a1

7 files changed

Lines changed: 770 additions & 565 deletions

File tree

configs/config.example.yaml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ chains:
8282
- url: "https://bsc.blockrazor.xyz"
8383
- url: "https://bnb.rpc.subquery.network/public"
8484

85+
conflux_mainnet:
86+
network_id: "conflux_mainnet"
87+
internal_code: "CONFLUX_MAINNET"
88+
type: "evm"
89+
start_block: 0
90+
poll_interval: "3s"
91+
nodes:
92+
- url: "https://evm.confluxrpc.com"
93+
- url: "https://conflux-espace-public.unifra.io"
94+
- url: "https://1rpc.io/cfx"
95+
96+
conflux_testnet:
97+
network_id: "conflux_testnet"
98+
internal_code: "CONFLUX_TESTNET"
99+
type: "evm"
100+
start_block: 0
101+
poll_interval: "3s"
102+
nodes:
103+
- url: "https://evmtestnet.confluxrpc.com"
104+
- url: "https://conflux-espace-testnet.public.blastapi.io"
105+
85106
bitcoin_testnet:
86107
network_id: "bitcoin_testnet"
87108
internal_code: "BTC_TESTNET"
@@ -322,6 +343,86 @@ chains:
322343
batch_size: 20
323344
concurrency: 4
324345

346+
xrp_mainnet:
347+
network_id: "xrp_mainnet"
348+
internal_code: "XRP_MAINNET"
349+
type: "xrp"
350+
start_block: 0
351+
poll_interval: "2s"
352+
nodes:
353+
- url: "https://xrplcluster.com"
354+
- url: "https://s1.ripple.com:51234"
355+
client:
356+
timeout: "15s"
357+
max_retries: 3
358+
retry_delay: "1s"
359+
throttle:
360+
rps: 40
361+
burst: 80
362+
batch_size: 20
363+
concurrency: 6
364+
parallel: true
365+
366+
xrp_testnet:
367+
network_id: "xrp_testnet"
368+
internal_code: "XRP_TESTNET"
369+
type: "xrp"
370+
start_block: 0
371+
poll_interval: "2s"
372+
nodes:
373+
- url: "https://s.altnet.rippletest.net:51234"
374+
- url: "https://testnet.xrpl-labs.com"
375+
client:
376+
timeout: "15s"
377+
max_retries: 3
378+
retry_delay: "1s"
379+
throttle:
380+
rps: 40
381+
burst: 80
382+
batch_size: 20
383+
concurrency: 6
384+
parallel: true
385+
386+
stellar_mainnet:
387+
network_id: "stellar_mainnet"
388+
internal_code: "STELLAR_MAINNET"
389+
type: "stellar"
390+
start_block: 0
391+
poll_interval: "2s"
392+
nodes:
393+
- url: "https://horizon.stellar.org"
394+
- url: "https://horizon.publicnode.com"
395+
client:
396+
timeout: "15s"
397+
max_retries: 3
398+
retry_delay: "1s"
399+
throttle:
400+
rps: 40
401+
burst: 80
402+
batch_size: 20
403+
concurrency: 6
404+
parallel: true
405+
406+
stellar_testnet:
407+
network_id: "stellar_testnet"
408+
internal_code: "STELLAR_TESTNET"
409+
type: "stellar"
410+
start_block: 0
411+
poll_interval: "2s"
412+
nodes:
413+
- url: "https://horizon-testnet.stellar.org"
414+
- url: "https://horizon-testnet.publicnode.com"
415+
client:
416+
timeout: "15s"
417+
max_retries: 3
418+
retry_delay: "1s"
419+
throttle:
420+
rps: 40
421+
burst: 80
422+
batch_size: 20
423+
concurrency: 6
424+
parallel: true
425+
325426
ton_mainnet:
326427
network_id: "ton"
327428
internal_code: "TON_MAINNET"

internal/indexer/stellar.go

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (s *StellarIndexer) convertLedger(
237237
}
238238

239239
var effects []stellar.Effect
240-
if strings.EqualFold(strings.TrimSpace(operation.Type), "create_claimable_balance") {
240+
if stellarOperationNeedsEffects(operation.Type) {
241241
effects, err = s.getCachedOperationEffects(ctx, effectsByOperation, effectsFetched, operation.ID)
242242
if err != nil {
243243
return nil, err
@@ -316,6 +316,15 @@ func (s *StellarIndexer) shouldProcessOperation(operation stellar.Operation) boo
316316
}
317317
}
318318

319+
func stellarOperationNeedsEffects(operationType string) bool {
320+
switch strings.ToLower(strings.TrimSpace(operationType)) {
321+
case "create_claimable_balance", "claim_claimable_balance":
322+
return true
323+
default:
324+
return false
325+
}
326+
}
327+
319328
func (s *StellarIndexer) getCachedTransactionDetail(
320329
ctx context.Context,
321330
cache map[string]*stellar.Transaction,
@@ -512,9 +521,9 @@ func (s *StellarIndexer) convertOperation(
512521
case "create_claimable_balance":
513522
return s.convertCreateClaimableBalanceOperation(operation, effects, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
514523
case "claim_claimable_balance":
515-
return s.convertClaimClaimableBalanceOperation(operation, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
524+
return s.convertClaimClaimableBalanceOperation(operation, effects, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
516525
case "clawback_claimable_balance":
517-
return s.convertClawbackClaimableBalanceOperation(operation, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
526+
return s.convertClawbackClaimableBalanceOperation(operation, effects, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
518527
default:
519528
return types.Transaction{}, false, nil
520529
}
@@ -595,14 +604,13 @@ func (s *StellarIndexer) convertCreateClaimableBalanceOperation(
595604
return types.Transaction{}, false, err
596605
}
597606

598-
shouldEmit := s.anyMonitoredAddress(claimants) || (s.config.TwoWayIndexing && s.isMonitoredAddress(sourceAccount))
607+
shouldEmit := s.config.TwoWayIndexing && s.isMonitoredAddress(sourceAccount)
599608
if !shouldEmit {
600609
return types.Transaction{}, false, nil
601610
}
602611

603612
tx := s.newOperationTransaction(operation, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
604613
tx.FromAddress = sourceAccount
605-
tx.ToAddress = stellarClaimableBalanceAddress(balanceID)
606614
tx.AssetAddress = assetAddress
607615
tx.Amount = amount
608616
tx.Type = txType
@@ -616,6 +624,7 @@ func (s *StellarIndexer) convertCreateClaimableBalanceOperation(
616624

617625
func (s *StellarIndexer) convertClaimClaimableBalanceOperation(
618626
operation stellar.Operation,
627+
effects []stellar.Effect,
619628
txDetail *stellar.Transaction,
620629
ledgerSequence uint64,
621630
blockHash string,
@@ -627,14 +636,25 @@ func (s *StellarIndexer) convertClaimClaimableBalanceOperation(
627636
return types.Transaction{}, false, nil
628637
}
629638
state, found, err := s.loadClaimableBalanceState(balanceID)
630-
if err != nil || !found {
639+
if err != nil {
631640
return types.Transaction{}, false, err
632641
}
633-
if err := s.deleteClaimableBalanceState(balanceID); err != nil {
634-
return types.Transaction{}, false, err
642+
if found {
643+
if err := s.deleteClaimableBalanceState(balanceID); err != nil {
644+
return types.Transaction{}, false, err
645+
}
646+
} else {
647+
state, found = stellarClaimableBalanceStateFromEffect(findStellarEffect(effects, "claimable_balance_claimed"))
648+
if !found {
649+
return types.Transaction{}, false, nil
650+
}
635651
}
636652

637653
claimant := normalizeStellarAddress(operation.Claimant)
654+
if claimant != "" {
655+
state.Claimants = []string{claimant}
656+
}
657+
638658
if claimant == "" || !s.isMonitoredAddress(claimant) {
639659
return types.Transaction{}, false, nil
640660
}
@@ -645,7 +665,6 @@ func (s *StellarIndexer) convertClaimClaimableBalanceOperation(
645665
}
646666

647667
tx := s.newOperationTransaction(operation, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
648-
tx.FromAddress = stellarClaimableBalanceAddress(balanceID)
649668
tx.ToAddress = claimant
650669
tx.AssetAddress = assetAddress
651670
tx.Amount = strings.TrimSpace(state.Amount)
@@ -657,6 +676,7 @@ func (s *StellarIndexer) convertClaimClaimableBalanceOperation(
657676

658677
func (s *StellarIndexer) convertClawbackClaimableBalanceOperation(
659678
operation stellar.Operation,
679+
effects []stellar.Effect,
660680
txDetail *stellar.Transaction,
661681
ledgerSequence uint64,
662682
blockHash string,
@@ -667,32 +687,16 @@ func (s *StellarIndexer) convertClawbackClaimableBalanceOperation(
667687
if balanceID == "" {
668688
return types.Transaction{}, false, nil
669689
}
670-
state, found, err := s.loadClaimableBalanceState(balanceID)
671-
if err != nil || !found {
672-
return types.Transaction{}, false, err
673-
}
674-
if err := s.deleteClaimableBalanceState(balanceID); err != nil {
690+
_, found, err := s.loadClaimableBalanceState(balanceID)
691+
if err != nil {
675692
return types.Transaction{}, false, err
676693
}
677-
678-
if !s.anyMonitoredAddress(state.Claimants) {
679-
return types.Transaction{}, false, nil
680-
}
681-
682-
txType, assetAddress, ok := stellarAssetFromOperation(state.Asset)
683-
if !ok || strings.TrimSpace(state.Amount) == "" {
684-
return types.Transaction{}, false, nil
694+
if found {
695+
if err := s.deleteClaimableBalanceState(balanceID); err != nil {
696+
return types.Transaction{}, false, err
697+
}
685698
}
686-
687-
tx := s.newOperationTransaction(operation, txDetail, ledgerSequence, blockHash, transferIndex, ledgerTimestamp)
688-
tx.FromAddress = stellarClaimableBalanceAddress(balanceID)
689-
tx.ToAddress = stellarBurnAddress
690-
tx.AssetAddress = assetAddress
691-
tx.Amount = strings.TrimSpace(state.Amount)
692-
tx.Type = txType
693-
tx.SetMetadata(types.MetadataKeySubtype, "clawback_claimable_balance")
694-
tx.SetMetadata(types.MetadataKeyClaimableID, balanceID)
695-
return tx, true, nil
699+
return types.Transaction{}, false, nil
696700
}
697701

698702
func (s *StellarIndexer) newOperationTransaction(
@@ -746,7 +750,7 @@ func (s *StellarIndexer) newOperationTransaction(
746750
func (s *StellarIndexer) fetchEffectsForOperations(ctx context.Context, operations []stellar.Operation) (map[string][]stellar.Effect, error) {
747751
effectsByOperation := make(map[string][]stellar.Effect)
748752
for _, operation := range operations {
749-
if !strings.EqualFold(strings.TrimSpace(operation.Type), "create_claimable_balance") {
753+
if !stellarOperationNeedsEffects(operation.Type) {
750754
continue
751755
}
752756
operationID := strings.TrimSpace(operation.ID)
@@ -859,6 +863,24 @@ func findStellarEffect(effects []stellar.Effect, effectType string) *stellar.Eff
859863
return nil
860864
}
861865

866+
func stellarClaimableBalanceStateFromEffect(effect *stellar.Effect) (stellarClaimableBalanceState, bool) {
867+
if effect == nil {
868+
return stellarClaimableBalanceState{}, false
869+
}
870+
871+
state := stellarClaimableBalanceState{
872+
Asset: strings.TrimSpace(effect.Asset),
873+
Amount: strings.TrimSpace(effect.Amount),
874+
}
875+
if claimant := normalizeStellarAddress(effect.Account); claimant != "" {
876+
state.Claimants = []string{claimant}
877+
}
878+
if state.Asset == "" || state.Amount == "" {
879+
return stellarClaimableBalanceState{}, false
880+
}
881+
return state, true
882+
}
883+
862884
func stellarTransferIndex(payment stellar.Payment, paymentIndex int) string {
863885
if pagingToken := strings.TrimSpace(payment.PagingToken); pagingToken != "" {
864886
return pagingToken

0 commit comments

Comments
 (0)