feat(txsHistory): add field receivedTime
This commit is contained in:
parent
ec2a0ecd8a
commit
7fe98256d2
11 changed files with 93 additions and 41 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -757,7 +757,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-bc-reader"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dubp",
|
||||
|
@ -803,7 +803,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-conf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dubp",
|
||||
|
@ -817,7 +817,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-core"
|
||||
version = "1.8.1"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"duniter-bc-reader",
|
||||
"duniter-conf",
|
||||
|
@ -830,7 +830,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-dbs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bincode",
|
||||
|
@ -853,7 +853,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-dbs-write-ops"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dubp",
|
||||
|
@ -868,7 +868,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-global"
|
||||
version = "1.8.1"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"async-rwlock",
|
||||
"dubp",
|
||||
|
@ -999,7 +999,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-mempools"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"dubp",
|
||||
"duniter-bc-reader",
|
||||
|
@ -1012,7 +1012,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-module"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-mutex",
|
||||
|
@ -1558,7 +1558,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "kv_typed"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"cfg-if 0.1.10",
|
||||
|
|
|
@ -49,7 +49,7 @@ use duniter_core::dbs::{
|
|||
cm_v1::CmV1DbReadable,
|
||||
txs_mp_v2::TxsMpV2DbReadable,
|
||||
},
|
||||
BlockMetaV2,
|
||||
BlockMetaV2, PendingTxDbV2,
|
||||
};
|
||||
use duniter_core::dbs::{
|
||||
kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, UtxoIdDbV2,
|
||||
|
@ -149,7 +149,7 @@ pub trait DbsReader {
|
|||
&self,
|
||||
txs_mp_db_ro: &TxsMpDb,
|
||||
pubkey: PublicKey,
|
||||
) -> KvResult<(Vec<TransactionDocumentV10>, Vec<TransactionDocumentV10>)>;
|
||||
) -> KvResult<(Vec<PendingTxDbV2>, Vec<PendingTxDbV2>)>;
|
||||
fn idty(
|
||||
&self,
|
||||
bc_db: &BcV2DbRo<FileBackend>,
|
||||
|
@ -302,7 +302,7 @@ impl DbsReader for DbsReaderImpl {
|
|||
&self,
|
||||
txs_mp_db_ro: &TxsMpDb,
|
||||
pubkey: PublicKey,
|
||||
) -> KvResult<(Vec<TransactionDocumentV10>, Vec<TransactionDocumentV10>)> {
|
||||
) -> KvResult<(Vec<PendingTxDbV2>, Vec<PendingTxDbV2>)> {
|
||||
self.get_txs_history_mempool_(txs_mp_db_ro, pubkey)
|
||||
}
|
||||
|
||||
|
|
|
@ -341,14 +341,14 @@ impl DbsReaderImpl {
|
|||
&self,
|
||||
txs_mp_db_ro: &TxsMpDb,
|
||||
pubkey: PublicKey,
|
||||
) -> KvResult<(Vec<TransactionDocumentV10>, Vec<TransactionDocumentV10>)> {
|
||||
) -> KvResult<(Vec<PendingTxDbV2>, Vec<PendingTxDbV2>)> {
|
||||
let sending = txs_mp_db_ro
|
||||
.txs_by_issuer()
|
||||
.get_ref_slice(&PubKeyKeyV2(pubkey), |hashs| {
|
||||
let mut sent = Vec::with_capacity(hashs.len());
|
||||
for hash in hashs {
|
||||
if let Some(tx_db) = txs_mp_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
|
||||
sent.push(tx_db.0);
|
||||
sent.push(tx_db);
|
||||
}
|
||||
}
|
||||
Ok(sent)
|
||||
|
@ -360,7 +360,7 @@ impl DbsReaderImpl {
|
|||
let mut pending = Vec::with_capacity(hashs.len());
|
||||
for hash in hashs {
|
||||
if let Some(tx_db) = txs_mp_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
|
||||
pending.push(tx_db.0);
|
||||
pending.push(tx_db);
|
||||
}
|
||||
}
|
||||
Ok(pending)
|
||||
|
@ -437,8 +437,8 @@ fn txs_history_bc_collect<I: Iterator<Item = KvResult<GvaTxDbV1>>>(
|
|||
pub struct TxsHistory {
|
||||
pub sent: Vec<GvaTxDbV1>,
|
||||
pub received: Vec<GvaTxDbV1>,
|
||||
pub sending: Vec<TransactionDocumentV10>,
|
||||
pub pending: Vec<TransactionDocumentV10>,
|
||||
pub sending: Vec<(TransactionDocumentV10, i64)>,
|
||||
pub pending: Vec<(TransactionDocumentV10, i64)>,
|
||||
}
|
||||
|
||||
// Needed for BMA only
|
||||
|
@ -484,7 +484,7 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
|
|||
let mut sent = Vec::with_capacity(hashs.len());
|
||||
for hash in hashs {
|
||||
if let Some(tx_db) = txs_mp_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
|
||||
sent.push(tx_db.0);
|
||||
sent.push((tx_db.doc, tx_db.received_time));
|
||||
}
|
||||
}
|
||||
Ok(sent)
|
||||
|
@ -496,7 +496,7 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
|
|||
let mut pending = Vec::with_capacity(hashs.len());
|
||||
for hash in hashs {
|
||||
if let Some(tx_db) = txs_mp_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
|
||||
pending.push(tx_db.0);
|
||||
pending.push((tx_db.doc, tx_db.received_time));
|
||||
}
|
||||
}
|
||||
Ok(pending)
|
||||
|
|
|
@ -78,9 +78,9 @@ pub(crate) enum TxDirection {
|
|||
#[derive(async_graphql::SimpleObject)]
|
||||
pub(crate) struct TxsHistoryMempool {
|
||||
/// Transactions sending
|
||||
pub(crate) sending: Vec<TxGva>,
|
||||
pub(crate) sending: Vec<PendingTxGva>,
|
||||
/// Transactions receiving
|
||||
pub(crate) receiving: Vec<TxGva>,
|
||||
pub(crate) receiving: Vec<PendingTxGva>,
|
||||
}
|
||||
|
||||
#[derive(Clone, async_graphql::SimpleObject)]
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use super::tx_gva::TxGva;
|
||||
use super::tx_gva::WrittenTxGva;
|
||||
use crate::*;
|
||||
use dubp::block::DubpBlockV10;
|
||||
use duniter_core::dbs::BlockMetaV2;
|
||||
|
@ -103,7 +103,7 @@ pub(crate) struct Block {
|
|||
pub excluded: Vec<String>,
|
||||
/// Certifications
|
||||
pub certifications: Vec<String>,
|
||||
pub transactions: Vec<TxGva>,
|
||||
pub transactions: Vec<WrittenTxGva>,
|
||||
}
|
||||
|
||||
impl From<&DubpBlockV10> for Block {
|
||||
|
|
|
@ -15,10 +15,62 @@
|
|||
|
||||
use crate::*;
|
||||
use dubp::documents::transaction::TransactionDocumentV10Stringified;
|
||||
use duniter_core::dbs::PendingTxDbV2;
|
||||
use duniter_gva_db::GvaTxDbV1;
|
||||
|
||||
#[derive(async_graphql::SimpleObject)]
|
||||
pub(crate) struct TxGva {
|
||||
#[graphql(name = "PendingTx")]
|
||||
pub(crate) struct PendingTxGva {
|
||||
/// Version.
|
||||
pub version: i32,
|
||||
/// Currency.
|
||||
pub currency: String,
|
||||
/// Blockstamp
|
||||
pub blockstamp: String,
|
||||
/// Locktime
|
||||
pub locktime: u64,
|
||||
/// Document issuers.
|
||||
pub issuers: Vec<String>,
|
||||
/// Transaction inputs.
|
||||
pub inputs: Vec<String>,
|
||||
/// Inputs unlocks.
|
||||
pub unlocks: Vec<String>,
|
||||
/// Transaction outputs.
|
||||
pub outputs: Vec<String>,
|
||||
/// Transaction comment
|
||||
pub comment: String,
|
||||
/// Document signatures
|
||||
pub signatures: Vec<String>,
|
||||
/// Transaction hash
|
||||
pub hash: String,
|
||||
/// Received time
|
||||
pub received_time: i64,
|
||||
}
|
||||
|
||||
impl From<&PendingTxDbV2> for PendingTxGva {
|
||||
fn from(db_tx: &PendingTxDbV2) -> Self {
|
||||
let tx_stringified = db_tx.doc.to_string_object();
|
||||
|
||||
PendingTxGva {
|
||||
version: 10,
|
||||
currency: tx_stringified.currency,
|
||||
blockstamp: tx_stringified.blockstamp,
|
||||
locktime: tx_stringified.locktime,
|
||||
issuers: tx_stringified.issuers,
|
||||
inputs: tx_stringified.inputs,
|
||||
unlocks: tx_stringified.unlocks,
|
||||
outputs: tx_stringified.outputs,
|
||||
comment: tx_stringified.comment,
|
||||
signatures: tx_stringified.signatures,
|
||||
hash: tx_stringified.hash.unwrap_or_default(),
|
||||
received_time: db_tx.received_time,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(async_graphql::SimpleObject)]
|
||||
#[graphql(name = "WrittenTx")]
|
||||
pub(crate) struct WrittenTxGva {
|
||||
/// Version.
|
||||
pub version: i32,
|
||||
/// Currency.
|
||||
|
@ -47,23 +99,23 @@ pub(crate) struct TxGva {
|
|||
pub written_time: Option<i64>,
|
||||
}
|
||||
|
||||
impl From<GvaTxDbV1> for TxGva {
|
||||
impl From<GvaTxDbV1> for WrittenTxGva {
|
||||
fn from(db_tx: GvaTxDbV1) -> Self {
|
||||
let mut self_: TxGva = (&db_tx.tx).into();
|
||||
let mut self_: WrittenTxGva = (&db_tx.tx).into();
|
||||
self_.written_block = Some(db_tx.written_block.to_string());
|
||||
self_.written_time = Some(db_tx.written_time);
|
||||
self_
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&TransactionDocumentV10> for TxGva {
|
||||
impl From<&TransactionDocumentV10> for WrittenTxGva {
|
||||
fn from(tx: &TransactionDocumentV10) -> Self {
|
||||
let tx_stringified = tx.to_string_object();
|
||||
Self::from(tx_stringified)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionDocumentV10Stringified> for TxGva {
|
||||
impl From<TransactionDocumentV10Stringified> for WrittenTxGva {
|
||||
fn from(tx_stringified: TransactionDocumentV10Stringified) -> Self {
|
||||
Self {
|
||||
version: 10,
|
||||
|
|
|
@ -38,7 +38,7 @@ use crate::entities::{
|
|||
block_gva::{Block, BlockMeta},
|
||||
idty_gva::Identity,
|
||||
network::{HeadGva, PeerCardGva, PeerWithHeads},
|
||||
tx_gva::TxGva,
|
||||
tx_gva::{PendingTxGva, WrittenTxGva},
|
||||
ud_gva::{CurrentUdGva, RevalUdGva, UdGva},
|
||||
utxos_gva::UtxosGva,
|
||||
AggregateSum, AmountWithBase, EdgeTx, RawTxOrChanges, Sum, TxDirection, TxsHistoryMempool,
|
||||
|
|
|
@ -26,7 +26,7 @@ impl MutationRoot {
|
|||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
raw_tx: String,
|
||||
) -> async_graphql::Result<TxGva> {
|
||||
) -> async_graphql::Result<WrittenTxGva> {
|
||||
let tx = TransactionDocumentV10::parse_from_raw_text(&raw_tx)?;
|
||||
|
||||
let data = ctx.data::<GvaSchemaData>()?;
|
||||
|
@ -46,7 +46,7 @@ impl MutationRoot {
|
|||
})
|
||||
.await??;
|
||||
|
||||
Ok(TxGva::from(&tx))
|
||||
Ok(WrittenTxGva::from(&tx))
|
||||
}
|
||||
|
||||
/// Process several transactions
|
||||
|
@ -55,7 +55,7 @@ impl MutationRoot {
|
|||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
raw_txs: Vec<String>,
|
||||
) -> async_graphql::Result<Vec<TxGva>> {
|
||||
) -> async_graphql::Result<Vec<WrittenTxGva>> {
|
||||
let txs = raw_txs
|
||||
.iter()
|
||||
.map(|raw_tx| TransactionDocumentV10::parse_from_raw_text(&raw_tx))
|
||||
|
@ -78,7 +78,7 @@ impl MutationRoot {
|
|||
.map(|()| tx)
|
||||
})
|
||||
.await??;
|
||||
processed_txs.push(TxGva::from(&tx));
|
||||
processed_txs.push(WrittenTxGva::from(&tx));
|
||||
}
|
||||
|
||||
Ok(processed_txs)
|
||||
|
|
|
@ -55,7 +55,7 @@ impl TxsHistoryBlockchainQueryInner {
|
|||
async fn both(
|
||||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
) -> async_graphql::Result<Connection<String, TxGva, EmptyFields, EdgeTx>> {
|
||||
) -> async_graphql::Result<Connection<String, WrittenTxGva, EmptyFields, EdgeTx>> {
|
||||
let start_time = std::time::Instant::now();
|
||||
|
||||
let data = ctx.data::<GvaSchemaData>()?;
|
||||
|
@ -146,7 +146,7 @@ impl TxsHistoryBlockchainQueryInner {
|
|||
async fn received(
|
||||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
) -> async_graphql::Result<Connection<String, TxGva, EmptyFields, EmptyFields>> {
|
||||
) -> async_graphql::Result<Connection<String, WrittenTxGva, EmptyFields, EmptyFields>> {
|
||||
let data = ctx.data::<GvaSchemaData>()?;
|
||||
let db_reader = data.dbs_reader();
|
||||
let pagination = self.pagination;
|
||||
|
@ -181,7 +181,7 @@ impl TxsHistoryBlockchainQueryInner {
|
|||
async fn sent(
|
||||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
) -> async_graphql::Result<Connection<String, TxGva, EmptyFields, EmptyFields>> {
|
||||
) -> async_graphql::Result<Connection<String, WrittenTxGva, EmptyFields, EmptyFields>> {
|
||||
let data = ctx.data::<GvaSchemaData>()?;
|
||||
let db_reader = data.dbs_reader();
|
||||
let pagination = self.pagination;
|
||||
|
@ -236,11 +236,11 @@ impl TxsHistoryMempoolQuery {
|
|||
Ok(TxsHistoryMempool {
|
||||
sending: sending
|
||||
.into_iter()
|
||||
.map(|db_tx| TxGva::from(&db_tx))
|
||||
.map(|db_tx| PendingTxGva::from(&db_tx))
|
||||
.collect(),
|
||||
receiving: pending
|
||||
.into_iter()
|
||||
.map(|db_tx| TxGva::from(&db_tx))
|
||||
.map(|db_tx| PendingTxGva::from(&db_tx))
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl PendingTxsSubscription {
|
|||
async fn receive_pending_txs(
|
||||
&self,
|
||||
ctx: &async_graphql::Context<'_>,
|
||||
) -> impl Stream<Item = async_graphql::Result<Vec<TxGva>>> {
|
||||
) -> impl Stream<Item = async_graphql::Result<Vec<WrittenTxGva>>> {
|
||||
create_subscription(
|
||||
ctx,
|
||||
|dbs| dbs.txs_mp_db.txs(),
|
||||
|
@ -37,7 +37,7 @@ impl PendingTxsSubscription {
|
|||
..
|
||||
} = event
|
||||
{
|
||||
txs.push(TxGva::from(&pending_tx.0));
|
||||
txs.push(WrittenTxGva::from(&pending_tx.doc));
|
||||
}
|
||||
}
|
||||
if txs.is_empty() {
|
||||
|
|
|
@ -206,7 +206,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
|
|||
.txs()
|
||||
.get(&duniter_core::dbs::HashKeyV2(hash))?
|
||||
{
|
||||
Ok(Some((tx.0, None)))
|
||||
Ok(Some((tx.doc, None)))
|
||||
} else if let Some(tx_db) = gva_db.txs().get(&duniter_core::dbs::HashKeyV2(hash))? {
|
||||
Ok(Some((tx_db.tx, Some(tx_db.written_block.number))))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue