Commit 24e794e6 authored by Éloïs's avatar Éloïs
Browse files

feat(bma): add field received to pending tx & writtenTime to tx

parent 1aefe50c
Pipeline #12306 failed with stages
in 60 minutes and 5 seconds
......@@ -864,7 +864,7 @@ dependencies = [
[[package]]
name = "dubp-wot"
version = "0.11.0"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#df4fa9e073efd91a9acbc7391fec5fc35c5e9872"
source = "git+https://git.duniter.org/nodes/rust/duniter-core#4f26e9e6f687f2c42adf7027bebb34f4ed58e600"
dependencies = [
"log",
"rayon",
......@@ -874,7 +874,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",
......@@ -885,7 +885,7 @@ dependencies = [
[[package]]
name = "duniter-bca"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"arrayvec",
......@@ -908,7 +908,7 @@ dependencies = [
[[package]]
name = "duniter-bca-types"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"arrayvec",
"bincode",
......@@ -940,7 +940,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",
......@@ -954,7 +954,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",
......@@ -991,7 +991,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",
......@@ -1014,7 +1014,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",
......@@ -1029,7 +1029,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",
......@@ -1042,7 +1042,7 @@ dependencies = [
[[package]]
name = "duniter-gva"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"arrayvec",
......@@ -1073,7 +1073,7 @@ dependencies = [
[[package]]
name = "duniter-gva-conf"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"duniter-core",
......@@ -1085,7 +1085,7 @@ dependencies = [
[[package]]
name = "duniter-gva-db"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"bincode",
"chrono",
......@@ -1102,7 +1102,7 @@ dependencies = [
[[package]]
name = "duniter-gva-dbs-reader"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"arrayvec",
......@@ -1116,7 +1116,7 @@ dependencies = [
[[package]]
name = "duniter-gva-gql"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"arrayvec",
......@@ -1137,7 +1137,7 @@ dependencies = [
[[package]]
name = "duniter-gva-indexer"
version = "0.1.0"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#ec2a0ecd8a17d373feeaf8d9253d281de2bd5bae"
source = "git+https://git.duniter.org/nodes/rust/modules/duniter-gva#7fe98256d2775eecaaedf03401f1a0ff9b08a49b"
dependencies = [
"anyhow",
"dubp",
......@@ -1152,6 +1152,7 @@ name = "duniter-integration-tests"
version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"dubp",
"duniter-core",
"duniter-server",
......@@ -1166,7 +1167,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",
......@@ -1179,7 +1180,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",
......@@ -1810,7 +1811,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",
......
......@@ -80,6 +80,7 @@ import { LevelDBMindex } from "./indexDAL/leveldb/LevelDBMindex";
import { ConfDAO } from "./indexDAL/abstract/ConfDAO";
import { ServerDAO } from "./server-dao";
import { PeerDTO } from "../dto/PeerDTO";
import { RustPendingTx } from "../../../neon/native/server";
const readline = require("readline");
const indexer = require("../indexer").Indexer;
......@@ -853,10 +854,12 @@ export class FileDAL implements ServerDAO {
return null;
} else {
let writtenBlock = tx.writtenBlock ? tx.writtenBlock : null;
let writtenTime = tx.writtenTime ? tx.writtenTime : tx.receivedTime;
let dbTx = DBTx.fromTransactionDTO(
await this.computeTxBlockstampTime(TransactionDTO.fromJSONObject(tx))
);
dbTx.block_number = writtenBlock;
dbTx.writtenOn = writtenTime || 0;
return dbTx;
}
}
......@@ -1394,7 +1397,10 @@ export class FileDAL implements ServerDAO {
}
saveTransaction(tx: TransactionDTO) {
return this.rustServer.addPendingTx(tx);
let currentTimestamp = Math.floor(Date.now() / 1000);
return this.rustServer.addPendingTx(
tx.toTransactionDTOV10(currentTimestamp)
);
}
async computeTxBlockstampTime(tx: TransactionDTO): Promise<TransactionDTO> {
......@@ -1413,6 +1419,17 @@ export class FileDAL implements ServerDAO {
let db_tx = DBTx.fromTransactionDTO(tx_dto);
db_tx.block_number = writtenBlockNumber;
db_tx.time = writtenTime;
db_tx.writtenOn = writtenTime;
return db_tx;
}
async RustPendingTxToDbTx(tx: RustPendingTx): Promise<DBTx> {
let receivedTime = tx.receivedTime;
let tx_dto = await this.computeTxBlockstampTime(
TransactionDTO.fromJSONObject(tx)
);
let db_tx = DBTx.fromTransactionDTO(tx_dto);
db_tx.received = receivedTime;
return db_tx;
}
......@@ -1436,20 +1453,10 @@ export class FileDAL implements ServerDAO {
res.received.map(async (tx) => this.RustDbTxToDbTx(tx))
);
history.sending = await Promise.all(
res.sending.map(async (tx) => {
let tx_dto = await this.computeTxBlockstampTime(
TransactionDTO.fromJSONObject(tx)
);
return DBTx.fromTransactionDTO(tx_dto);
})
res.sending.map(async (tx) => this.RustPendingTxToDbTx(tx))
);
history.pending = await Promise.all(
res.pending.map(async (tx) => {
let tx_dto = await this.computeTxBlockstampTime(
TransactionDTO.fromJSONObject(tx)
);
return DBTx.fromTransactionDTO(tx_dto);
})
res.pending.map(async (tx) => this.RustPendingTxToDbTx(tx))
);
return history;
}
......
......@@ -306,6 +306,25 @@ export class TransactionDTO implements Cloneable {
);
}
toTransactionDTOV10(receivedTime: number): TransactionDTOV10 {
return {
currency: this.currency,
locktime: this.locktime,
hash: this.hash,
blockstamp: this.blockstamp,
blockstampTime: this.blockstampTime,
issuers: this.issuers,
inputs: this.inputs,
unlocks: this.unlocks,
outputs: this.outputs,
signatures: this.signatures,
comment: this.comment,
receivedTime: receivedTime,
writtenBlock: undefined,
writtenTime: undefined,
};
}
static toRAW(json: TransactionDTO, noSig = false) {
let raw = "";
raw += "Version: " + json.version + "\n";
......
......@@ -280,6 +280,8 @@ export class BMAPI extends stream.Transform {
if (this.conf.nobma) {
this.conf.nobma = false;
}
this.server.conf.ipv4 = "127.0.0.1";
this.server.conf.port = 10901;
if (this.server.conf.upnp) {
this.server.conf.upnp = false;
}
......
......@@ -18,6 +18,7 @@ import { TransactionDTO } from "../../../../lib/dto/TransactionDTO";
import {
HttpSources,
HttpTransaction,
HttpTransactionPending,
HttpTxHistory,
HttpTxOfHistory,
HttpTxPending,
......@@ -28,7 +29,7 @@ import { Underscore } from "../../../../lib/common-libs/underscore";
const http2raw = require("../http2raw");
export class TransactionBinding extends AbstractController {
async parseTransaction(req: any): Promise<HttpTransaction> {
async parseTransaction(req: any): Promise<HttpTransactionPending> {
const res = await this.pushEntity(
req,
http2raw.transaction,
......@@ -36,7 +37,6 @@ export class TransactionBinding extends AbstractController {
);
return {
version: res.version,
currency: res.currency,
issuers: res.issuers,
inputs: res.inputs,
outputs: res.outputs,
......@@ -45,8 +45,7 @@ export class TransactionBinding extends AbstractController {
comment: res.comment,
locktime: res.locktime,
hash: res.hash,
written_block: res.blockNumber,
raw: res.getRaw(),
receivedTime: Math.floor(Date.now() / 1000),
};
}
......@@ -72,8 +71,6 @@ export class TransactionBinding extends AbstractController {
version: tx.version,
currency: tx.currency,
locktime: tx.locktime,
// blockstamp: tx.blockstamp,
// blockstampTime: tx.blockstampTime,
issuers: tx.issuers,
inputs: tx.inputs,
outputs: tx.outputs,
......@@ -81,10 +78,8 @@ export class TransactionBinding extends AbstractController {
signatures: tx.signatures,
comment: tx.comment,
hash: tx.hash,
// time: tx.time,
// block_number: tx.block_number,
written_block: tx.block_number,
// received: tx.received,
writtenTime: tx.writtenOn,
raw: "",
};
}
......@@ -155,6 +150,7 @@ export class TransactionBinding extends AbstractController {
blockstampTime: tx.blockstampTime,
signatures: tx.signatures,
hash: tx.hash,
receivedTime: t.receivedTime || 0,
};
}),
};
......@@ -194,6 +190,7 @@ function dbtx2HttpTxOfHistory(tx: DBTx): HttpTxOfHistory {
hash: tx.hash,
time: tx.time,
block_number: tx.block_number,
received: tx.received,
receivedTime: tx.received,
writtenTime: tx.writtenOn,
};
}
......@@ -776,6 +776,7 @@ export interface HttpTransaction {
signatures: string[];
raw: string;
written_block: number | null;
writtenTime: number;
hash: string;
}
......@@ -789,6 +790,7 @@ export interface HttpTransactionPending {
locktime: number;
signatures: string[];
hash: string;
receivedTime: number;
}
export const Source = {
......@@ -846,13 +848,14 @@ export interface HttpTxOfHistory {
outputs: string[];
comment: string;
locktime: number;
received: number;
signatures: string[];
hash: string;
block_number: number | null;
time: number | null;
blockstamp: string;
blockstampTime: number | null;
receivedTime: number;
writtenTime: number;
}
export const TxHistory = {
......
......@@ -78,10 +78,27 @@ export class RustDbTx {
unlocks: string[];
signatures: string[];
comment: string;
receivedTime: number;
writtenBlockNumber: number;
writtenTime: number;
}
export class RustPendingTx {
version: number;
currency: string;
locktime: number;
hash: string;
blockstamp: string;
blockstampTime: number;
issuers: string[];
inputs: string[];
outputs: string[];
unlocks: string[];
signatures: string[];
comment: string;
receivedTime: number;
}
export class RustServerConf {
command: string | null
currency: string
......@@ -92,8 +109,8 @@ export class RustServerConf {
export class TxsHistory {
sent: RustDbTx[];
received: RustDbTx[];
sending: TransactionDTOV10[];
pending: TransactionDTOV10[];
sending: RustPendingTx[];
pending: RustPendingTx[];
}
export class RustServer {
......
......@@ -219,7 +219,7 @@ declare_types! {
};
match res {
Ok(txs) => {
let txs: Vec<_> = txs.into_iter().map(|tx| tx.0.to_string_object()).collect();
let txs: Vec<_> = txs.into_iter().map(|tx| tx.doc.to_string_object()).collect();
Ok(neon_serde::to_value(&mut cx, &txs)?)
},
Err(e) => cx.throw_error(format!("{}", e)),
......@@ -279,8 +279,16 @@ declare_types! {
.into_iter()
.map(|(tx, wb, wt)| DbTx::v10(tx.to_string_object(), tx.get_hash(), wb.number.0, wt))
.collect();
let sending: Vec<_> = txs_history.sending.into_iter().map(|tx| tx.to_string_object()).collect();
let pending: Vec<_> = txs_history.pending.into_iter().map(|tx| tx.to_string_object()).collect();
let sending: Vec<_> = txs_history
.sending
.into_iter()
.map(|(tx, received_time)| PendingTx::v10( tx.to_string_object(), tx.get_hash(), received_time))
.collect();
let pending: Vec<_> = txs_history
.pending
.into_iter()
.map(|(tx, received_time)| PendingTx::v10( tx.to_string_object(), tx.get_hash(), received_time))
.collect();
Ok(neon_serde::to_value(&mut cx, &TxsHistoryStringified {
sent,
......@@ -430,7 +438,7 @@ impl DbTx {
written_block_number: u32,
written_time: i64,
) -> Self {
DbTx {
Self {
version: 10,
currency: tx_doc.currency,
blockstamp: tx_doc.blockstamp,
......@@ -448,6 +456,46 @@ impl DbTx {
}
}
#[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PendingTx {
pub version: u32,
pub currency: String,
pub blockstamp: String,
pub locktime: u64,
pub issuers: Vec<String>,
pub inputs: Vec<String>,
pub unlocks: Vec<String>,
pub outputs: Vec<String>,
pub comment: String,
pub signatures: Vec<String>,
pub hash: String,
pub received_time: i64,
}
impl PendingTx {
pub fn v10(
tx_doc: TransactionDocumentV10Stringified,
tx_hash: Hash,
received_time: i64,
) -> Self {
Self {
version: 10,
currency: tx_doc.currency,
blockstamp: tx_doc.blockstamp,
locktime: tx_doc.locktime,
issuers: tx_doc.issuers,
inputs: tx_doc.inputs,
unlocks: tx_doc.unlocks,
outputs: tx_doc.outputs,
comment: tx_doc.comment,
signatures: tx_doc.signatures,
hash: tx_hash.to_hex(),
received_time,
}
}
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
......@@ -481,6 +529,6 @@ struct RustServerConfStringified {
struct TxsHistoryStringified {
sent: Vec<DbTx>,
received: Vec<DbTx>,
sending: Vec<TransactionDocumentV10Stringified>,
pending: Vec<TransactionDocumentV10Stringified>,
sending: Vec<PendingTx>,
pending: Vec<PendingTx>,
}
......@@ -12,7 +12,9 @@ export class TransactionDTOV10 {
unlocks: string[];
signatures: string[];
comment: string;
receivedTime?: number;
writtenBlock?: number;
writtenTime?: number;
}
export function rawTxParseAndVerify(raw: string, currency?: string): TransactionDTOV10;
......
......@@ -53,7 +53,7 @@ impl DuniterServer {
for event in events.deref() {
match event {
duniter_core::dbs::databases::txs_mp_v2::TxsEvent::Upsert { key, value } => {
new_pending_txs.insert(key.0, value.0.clone());
new_pending_txs.insert(key.0, value.doc.clone());
}
duniter_core::dbs::databases::txs_mp_v2::TxsEvent::Remove { key } => {
new_pending_txs.remove(&key.0);
......@@ -73,7 +73,7 @@ impl DuniterServer {
.execute(move |dbs| {
dbs.txs_mp_db.txs().iter(.., |it| {
it.values()
.filter_ok(|tx| tx.0.version() >= min_version)
.filter_ok(|tx| tx.doc.version() >= min_version)
.collect()
})
})
......
......@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
anyhow = "1.0.34"
chrono = "0.4"
dubp = { version = "0.53.1", features = ["duniter"] }
duniter-core = { git = "https://git.duniter.org/nodes/rust/duniter-core", features = ["bc-writer"] }
duniter-server = { path = "../../duniter-server", features = ["gva"] }
......
......@@ -59,12 +59,13 @@ mod tests {
}
.build_with_signature(smallvec![]);
let received_time = chrono::offset::Utc::now().timestamp();
server.add_pending_tx_force(tx.clone())?;
let txs_history = server.get_transactions_history(PublicKey::default())?;
tx.get_hash();
assert_eq!(txs_history.sending, vec![tx]);
assert_eq!(txs_history.sending, vec![(tx, received_time)]);
server.remove_all_pending_txs()?;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment