-
Notifications
You must be signed in to change notification settings - Fork 129
WIP: Implementation for ocean-API transaction module #2781
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
57329f5
added transaction index
nagarajm22 5206887
added transaction api implementation
nagarajm22 374bcad
fixed .cpp file formats
nagarajm22 b3819f2
fixed id to Txid
nagarajm22 3a5ebd1
added transction list method by block_hash
nagarajm22 6d5fca3
added transaction indexing
nagarajm22 cd9cb69
removed transaction by block_hash from trx module
nagarajm22 59b1a42
update txid strong type
nagarajm22 d3804ce
removed method list_trasnction_txid
nagarajm22 2cfe153
added vin and vout index in transaction with query
nagarajm22 cc2dc0e
updated vin and vout table as Txid
nagarajm22 2882de5
fixed conflicts in transaction branch
nagarajm22 8a98719
fixed fmt
nagarajm22 c254fac
Restore cpp fmt
Jouzo 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,94 @@ | ||
| use bitcoin::{blockdata::locktime::absolute::LockTime, Txid}; | ||
| use dftx_rs::{Block, Transaction}; | ||
| use log::debug; | ||
|
|
||
| use super::BlockContext; | ||
| use crate::{ | ||
| indexer::Result, | ||
| model::{ | ||
| Transaction as TrasnactionMapper, TransactionVin, TransactionVinScript, TransactionVinVout, | ||
| TransactionVinVoutScript, TransactionVout, TransactionVoutScript, | ||
| }, | ||
| repository::RepositoryOps, | ||
| SERVICES, | ||
| }; | ||
|
|
||
| pub fn index_transactions(ctx: &BlockContext, tx: Transaction) -> Result<()> { | ||
| debug!("[CreateTransaction] Indexing..."); | ||
| let tx_id = tx.txid(); | ||
|
|
||
| let lock_time_as_i32 = match tx.lock_time { | ||
| LockTime::Blocks(value) => value.to_consensus_u32(), | ||
| LockTime::Seconds(value) => value.to_consensus_u32(), | ||
| }; | ||
| let total_vout_value: u64 = tx.output.iter().map(|output| output.value.to_sat()).sum(); | ||
| let weight = tx.weight(); | ||
| let weight_i32 = weight.to_vbytes_ceil() as i32; | ||
|
|
||
| let trx = TrasnactionMapper { | ||
| id: tx_id, | ||
| order: 0, | ||
| block: ctx.clone(), | ||
| txid: tx_id.to_string(), | ||
| hash: ctx.hash.to_string(), | ||
| version: tx.version.0, | ||
| size: tx.total_size() as i32, | ||
| v_size: tx.vsize() as i32, | ||
| weight: weight_i32, | ||
| total_vout_value: total_vout_value.to_string(), | ||
| lock_time: lock_time_as_i32 as i32, | ||
| vin_count: tx.input.len() as i32, | ||
| vout_count: tx.output.len() as i32, | ||
| }; | ||
| // Index transaction | ||
| SERVICES.transaction.by_id.put(&tx_id, &trx)?; | ||
| // Indexing transaction vin | ||
| for (vin_idx, vin) in tx.input.iter().enumerate() { | ||
| let trx_vin = TransactionVin { | ||
| id: format!("{}-{}", tx_id, vin_idx), | ||
| txid: tx_id.to_string(), | ||
| coinbase: vin.script_sig.to_string(), | ||
| vout: TransactionVinVout { | ||
| id: format!("{}-{}-vout", tx_id, vin_idx), | ||
| txid: tx_id.to_string(), | ||
| n: vin.previous_output.vout as i32, | ||
| value: "0".to_string(), | ||
| token_id: 0, | ||
| script: TransactionVinVoutScript { | ||
| hex: vin.script_sig.to_string(), | ||
| }, | ||
| }, | ||
| script: TransactionVinScript { | ||
| hex: vin.script_sig.to_string(), | ||
| }, | ||
| tx_in_witness: vec![], | ||
| sequence: vin.sequence.to_string(), | ||
| }; | ||
|
|
||
| SERVICES.transaction.vin_by_id.put(&tx_id, &trx_vin)?; | ||
| } | ||
| // Index transaction vout | ||
| for (vout_idx, vout) in tx.output.iter().enumerate() { | ||
| let trx_vout = TransactionVout { | ||
| id: format!("{}-{}", tx_id, vout_idx), | ||
| txid: tx_id.to_string(), | ||
| n: vout_idx as i32, | ||
| value: vout.value.to_string(), | ||
| token_id: 0, | ||
| script: TransactionVoutScript { | ||
| hex: vout.script_pubkey.to_string(), | ||
| r#type: "pubkey".to_string(), | ||
| }, | ||
| }; | ||
| SERVICES.transaction.vout_by_id.put(&tx_id, &trx_vout)?; | ||
| // .put(&format!("{}-{}", tx_id, vout_idx), &trx_vout)?; //need | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn invalidate_transaction(ctx: &BlockContext, tx: Txid, idx: usize) -> Result<()> { | ||
| debug!("[CreateMasternode] Invalidating..."); | ||
| SERVICES.transaction.by_id.delete(&tx)?; | ||
| Ok(()) | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,27 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use ain_db::LedgerColumn; | ||
| use ain_macros::Repository; | ||
| use bitcoin::{BlockHash, Txid}; | ||
|
|
||
| use super::RepositoryOps; | ||
| use crate::{ | ||
| model::Transaction, | ||
| storage::{columns, ocean_store::OceanStore}, | ||
| Result, | ||
| }; | ||
| #[derive(Repository)] | ||
| #[repository(K = "Txid", V = "Transaction")] | ||
| pub struct TransactionRepository { | ||
| pub store: Arc<OceanStore>, | ||
| col: LedgerColumn<columns::Transaction>, | ||
| } | ||
|
|
||
| impl TransactionRepository { | ||
| pub fn new(store: Arc<OceanStore>) -> Self { | ||
| Self { | ||
| col: store.column(), | ||
| store, | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,28 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use ain_db::LedgerColumn; | ||
| use ain_macros::Repository; | ||
| use bitcoin::Txid; | ||
|
|
||
| use super::RepositoryOps; | ||
| use crate::{ | ||
| model::TransactionVin, | ||
| storage::{columns, ocean_store::OceanStore}, | ||
| Result, | ||
| }; | ||
|
|
||
| #[derive(Repository)] | ||
| #[repository(K = "Txid", V = "TransactionVin")] | ||
| pub struct TransactionVinRepository { | ||
| pub store: Arc<OceanStore>, | ||
| col: LedgerColumn<columns::TransactionVin>, | ||
| } | ||
|
|
||
| impl TransactionVinRepository { | ||
| pub fn new(store: Arc<OceanStore>) -> Self { | ||
| Self { | ||
| col: store.column(), | ||
| store, | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,28 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use ain_db::LedgerColumn; | ||
| use ain_macros::Repository; | ||
| use bitcoin::Txid; | ||
|
|
||
| use super::RepositoryOps; | ||
| use crate::{ | ||
| model::TransactionVout, | ||
| storage::{columns, ocean_store::OceanStore}, | ||
| Result, | ||
| }; | ||
|
|
||
| #[derive(Repository)] | ||
| #[repository(K = "Txid", V = "TransactionVout")] | ||
| pub struct TransactionVoutRepository { | ||
| pub store: Arc<OceanStore>, | ||
| col: LedgerColumn<columns::TransactionVout>, | ||
| } | ||
|
|
||
| impl TransactionVoutRepository { | ||
| pub fn new(store: Arc<OceanStore>) -> Self { | ||
| Self { | ||
| col: store.column(), | ||
| store, | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.