Skip to content

Commit

Permalink
Merge pull request #7 from AlgoNode/sync-with-upstream
Browse files Browse the repository at this point in the history
Sync with upstream
  • Loading branch information
urtho authored Dec 27, 2024
2 parents 27d53ad + 92a1d78 commit dd7c45c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 337 deletions.
49 changes: 46 additions & 3 deletions plugin/exporter/idb/cockroach/internal/writer/write_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func transactionAssetID(stxnad *types.SignedTxnWithAD, intra uint, block *types.
case types.ApplicationCallTx:
assetid = uint64(stxnad.Txn.ApplicationID)
if assetid == 0 {
assetid = uint64(stxnad.ApplyData.ApplicationID)
assetid = stxnad.ApplyData.ApplicationID
}
if assetid == 0 {
if block == nil {
Expand All @@ -42,7 +42,7 @@ func transactionAssetID(stxnad *types.SignedTxnWithAD, intra uint, block *types.
case types.AssetConfigTx:
assetid = uint64(stxnad.Txn.ConfigAsset)
if assetid == 0 {
assetid = uint64(stxnad.ApplyData.ConfigAsset)
assetid = stxnad.ApplyData.ConfigAsset
}
if assetid == 0 {
if block == nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func yieldTransactions(ctx context.Context, block *types.Block, modifiedTxns []t
}

txn := &stxnad.Txn
typeenum, ok := idb.GetTypeEnum(types.TxType(txn.Type))
typeenum, ok := idb.GetTypeEnum(txn.Type)
if !ok {
return fmt.Errorf("yieldTransactions() get type enum")
}
Expand Down Expand Up @@ -153,9 +153,52 @@ func yieldTransactions(ctx context.Context, block *types.Block, modifiedTxns []t
}
}

if block.ProposerPayout > 0 {
stxnad := SignedTransactionFromBlockPayout(block)
typeenum, ok := idb.GetTypeEnum(stxnad.Txn.Type)
if !ok {
return fmt.Errorf("yieldTransactions() ProposerPayout get type enum - should NEVER happen")
}
id := crypto.TransactionIDString(stxnad.Txn)
extra := idb.TxnExtra{}
row := []interface{}{
uint64(block.Round), intra, int(typeenum), 0, id,
encoding.EncodeSignedTxnWithAD(stxnad),
encoding.EncodeTxnExtra(&extra)}
select {
case <-ctx.Done():
return fmt.Errorf("yieldTransactions() ProposerPayout ctx.Err(): %w", ctx.Err())
case outCh <- row:
}
}

return nil
}

// SignedTransactionFromBlockPayout creates a synthetic transaction for the proposer payout.
func SignedTransactionFromBlockPayout(block *types.Block) types.SignedTxnWithAD {
stxnad := types.SignedTxnWithAD{
SignedTxn: types.SignedTxn{
Txn: types.Transaction{
Type: types.PaymentTx,
Header: types.Header{
Sender: block.FeeSink,
Note: []byte("ProposerPayout for Round " + fmt.Sprint(block.Round)),
FirstValid: block.Round,
LastValid: block.Round,
GenesisID: block.GenesisID,
GenesisHash: block.GenesisHash,
},
PaymentTxnFields: types.PaymentTxnFields{
Receiver: block.Proposer,
Amount: block.ProposerPayout,
},
},
},
}
return stxnad
}

// AddTransactions adds transactions from `block` to the database.
// `modifiedTxns` contains enhanced apply data generated by evaluator.
func AddTransactions(block *types.Block, modifiedTxns []types.SignedTxnInBlock, tx pgx.Tx) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func AddTransactionParticipation(block *types.Block, tx pgx.Tx) error {
next, rows = addInnerTransactionParticipation(&stxnib.SignedTxnWithAD, uint64(block.Round), next+1, rows)
}

if block.ProposerPayout > 0 {
// FeeSink is the sender, Proposer is the receiver.
participants := []types.Address{block.FeeSink, block.Proposer}
for j := range participants {
rows = append(rows, []interface{}{participants[j][:], uint64(block.Round), next})
}
}

_, err := tx.CopyFrom(
context.Background(),
pgx.Identifier{"txn_participation"},
Expand Down
45 changes: 0 additions & 45 deletions plugin/exporter/idb/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,6 @@ func (db *dummyIndexerDb) GetNextRoundToLoad() (uint64, error) {
return 0, nil
}

// GetSpecialAccounts is part of idb.IndexerDb
func (db *dummyIndexerDb) GetSpecialAccounts(ctx context.Context) (types.SpecialAddresses, error) {
return types.SpecialAddresses{}, nil
}

// GetBlock is part of idb.IndexerDB
func (db *dummyIndexerDb) GetBlock(ctx context.Context, round uint64, options idb.GetBlockOptions) (blockHeader sdk.BlockHeader, transactions []idb.TxnRow, err error) {
return sdk.BlockHeader{}, nil, nil
}

// Transactions is part of idb.IndexerDB
func (db *dummyIndexerDb) Transactions(ctx context.Context, tf idb.TransactionFilter) (<-chan idb.TxnRow, uint64) {
return nil, 0
}

// GetAccounts is part of idb.IndexerDB
func (db *dummyIndexerDb) GetAccounts(ctx context.Context, opts idb.AccountQueryOptions) (<-chan idb.AccountRow, uint64) {
return nil, 0
}

// Assets is part of idb.IndexerDB
func (db *dummyIndexerDb) Assets(ctx context.Context, filter idb.AssetsQuery) (<-chan idb.AssetRow, uint64) {
return nil, 0
}

// AssetBalances is part of idb.IndexerDB
func (db *dummyIndexerDb) AssetBalances(ctx context.Context, abq idb.AssetBalanceQuery) (<-chan idb.AssetBalanceRow, uint64) {
return nil, 0
}

// Applications is part of idb.IndexerDB
func (db *dummyIndexerDb) Applications(ctx context.Context, filter idb.ApplicationQuery) (<-chan idb.ApplicationRow, uint64) {
return nil, 0
}

// AppLocalState is part of idb.IndexerDB
func (db *dummyIndexerDb) AppLocalState(ctx context.Context, filter idb.ApplicationQuery) (<-chan idb.AppLocalStateRow, uint64) {
return nil, 0
}

// ApplicationBoxes isn't currently implemented
func (db *dummyIndexerDb) ApplicationBoxes(ctx context.Context, filter idb.ApplicationBoxQuery) (<-chan idb.ApplicationBoxRow, uint64) {
panic("not implemented")
}

// Health is part of idb.IndexerDB
func (db *dummyIndexerDb) Health(ctx context.Context) (state idb.Health, err error) {
return idb.Health{}, nil
Expand Down
Loading

0 comments on commit dd7c45c

Please sign in to comment.