Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter-gva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
modules
duniter-gva
Commits
2bcbe90c
Commit
2bcbe90c
authored
2 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[enh] add `get_written_transactions_for_bma()` and `get_pending_transactions_for_bma()` - close
#1
parent
c8d178fd
No related branches found
No related tags found
1 merge request
!5
feat(bma) add `get_written_transactions_for_bma()` and `get_pending_transactions_for_bma()` - close #1
Pipeline
#31801
failed
2 years ago
Stage: tests
Stage: quality
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dbs-reader/src/txs_history.rs
+47
-4
47 additions, 4 deletions
dbs-reader/src/txs_history.rs
src/lib.rs
+65
-2
65 additions, 2 deletions
src/lib.rs
with
112 additions
and
6 deletions
dbs-reader/src/txs_history.rs
+
47
−
4
View file @
2bcbe90c
...
@@ -446,10 +446,40 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
...
@@ -446,10 +446,40 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
gva_db_ro
:
&
GvaDb
,
gva_db_ro
:
&
GvaDb
,
txs_mp_db_ro
:
&
TxsMpDb
,
txs_mp_db_ro
:
&
TxsMpDb
,
pubkey
:
PublicKey
,
pubkey
:
PublicKey
,
)
->
KvResult
<
TxsHistory
>
{
// Get written TX
let
TxsHistory
{
sent
,
received
,
..
}
=
get_written_transactions_for_bma
(
gva_db_ro
,
pubkey
)
?
;
// Get pending TX
let
TxsHistory
{
sending
,
pending
,
..
}
=
get_pending_transactions_for_bma
(
txs_mp_db_ro
,
pubkey
)
?
;
// Return all (written + pending)
Ok
(
TxsHistory
{
sent
,
received
,
sending
,
pending
,
})
}
// Needed for BMA only
pub
fn
get_written_transactions_for_bma
<
GvaDb
:
GvaV1DbReadable
>
(
gva_db_ro
:
&
GvaDb
,
pubkey
:
PublicKey
,
)
->
KvResult
<
TxsHistory
>
{
get_written_transactions_for_bma_with_range
(
gva_db_ro
,
pubkey
,
0
,
u32
::
MAX
)
}
// Needed for BMA only
pub
fn
get_written_transactions_for_bma_with_range
<
GvaDb
:
GvaV1DbReadable
>
(
gva_db_ro
:
&
GvaDb
,
pubkey
:
PublicKey
,
start_block
:
u32
,
end_block
:
u32
,
)
->
KvResult
<
TxsHistory
>
{
)
->
KvResult
<
TxsHistory
>
{
let
script_hash
=
Hash
::
compute
(
WalletScriptV10
::
single_sig
(
pubkey
)
.to_string
()
.as_bytes
());
let
script_hash
=
Hash
::
compute
(
WalletScriptV10
::
single_sig
(
pubkey
)
.to_string
()
.as_bytes
());
let
start_k
=
WalletHashWithBnV1Db
::
new
(
script_hash
,
BlockNumber
(
0
));
let
start_k
=
WalletHashWithBnV1Db
::
new
(
script_hash
,
BlockNumber
(
start_block
));
let
end_k
=
WalletHashWithBnV1Db
::
new
(
script_hash
,
BlockNumber
(
u32
::
MAX
));
let
end_k
=
WalletHashWithBnV1Db
::
new
(
script_hash
,
BlockNumber
(
end_block
));
let
sent
=
gva_db_ro
let
sent
=
gva_db_ro
.txs_by_issuer
()
.txs_by_issuer
()
...
@@ -478,6 +508,19 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
...
@@ -478,6 +508,19 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
})
})
.flatten_ok
()
.flatten_ok
()
.collect
::
<
KvResult
<
Vec
<
_
>>>
()
?
;
.collect
::
<
KvResult
<
Vec
<
_
>>>
()
?
;
Ok
(
TxsHistory
{
sent
,
received
,
sending
:
Vec
::
new
(),
pending
:
Vec
::
new
(),
})
}
// Needed for BMA only
pub
fn
get_pending_transactions_for_bma
<
TxsMpDb
:
TxsMpV2DbReadable
>
(
txs_mp_db_ro
:
&
TxsMpDb
,
pubkey
:
PublicKey
,
)
->
KvResult
<
TxsHistory
>
{
let
sending
=
txs_mp_db_ro
let
sending
=
txs_mp_db_ro
.txs_by_issuer
()
.txs_by_issuer
()
.get_ref_slice
(
&
PubKeyKeyV2
(
pubkey
),
|
hashs
|
{
.get_ref_slice
(
&
PubKeyKeyV2
(
pubkey
),
|
hashs
|
{
...
@@ -503,8 +546,8 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
...
@@ -503,8 +546,8 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
})
?
})
?
.unwrap_or_default
();
.unwrap_or_default
();
Ok
(
TxsHistory
{
Ok
(
TxsHistory
{
sent
,
sent
:
Vec
::
new
()
,
received
,
received
:
Vec
::
new
()
,
sending
,
sending
,
pending
,
pending
,
})
})
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
65
−
2
View file @
2bcbe90c
...
@@ -170,7 +170,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
...
@@ -170,7 +170,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
}
}
Ok
(())
Ok
(())
}
}
// Needed for BMA only
, will be removed when the migration is complete.
// Needed for BMA only
fn
get_transactions_history_for_bma
(
fn
get_transactions_history_for_bma
(
dbs_pool
:
&
fast_threadpool
::
ThreadPoolSyncHandler
<
SharedDbs
<
FileBackend
>>
,
dbs_pool
:
&
fast_threadpool
::
ThreadPoolSyncHandler
<
SharedDbs
<
FileBackend
>>
,
profile_path_opt
:
Option
<&
Path
>
,
profile_path_opt
:
Option
<&
Path
>
,
...
@@ -216,7 +216,70 @@ impl duniter_core::module::DuniterModule for GvaModule {
...
@@ -216,7 +216,70 @@ impl duniter_core::module::DuniterModule for GvaModule {
pending
,
pending
,
}))
}))
}
}
// Needed for BMA only, will be removed when the migration is complete.
// Needed for BMA only
fn
get_written_transactions_for_bma
(
profile_path_opt
:
Option
<&
Path
>
,
pubkey
:
PublicKey
,
start_block
:
u32
,
end_block
:
u32
,
)
->
KvResult
<
Option
<
duniter_core
::
module
::
TxsHistoryForBma
>>
{
let
gva_db
=
get_gva_db_ro
(
profile_path_opt
);
let
duniter_gva_dbs_reader
::
txs_history
::
TxsHistory
{
sent
,
received
,
..
}
=
duniter_gva_dbs_reader
::
txs_history
::
get_written_transactions_for_bma_with_range
(
gva_db
,
pubkey
,
start_block
,
end_block
,
)
?
;
Ok
(
Some
(
duniter_core
::
module
::
TxsHistoryForBma
{
sent
:
sent
.into_iter
()
.map
(
|
GvaTxDbV1
{
tx
,
written_block
,
written_time
,
}|
(
tx
,
written_block
,
written_time
),
)
.collect
(),
received
:
received
.into_iter
()
.map
(
|
GvaTxDbV1
{
tx
,
written_block
,
written_time
,
}|
(
tx
,
written_block
,
written_time
),
)
.collect
(),
sending
:
Vec
::
new
(),
pending
:
Vec
::
new
(),
}))
}
// Needed for BMA only
fn
get_pending_transactions_for_bma
(
dbs_pool
:
&
fast_threadpool
::
ThreadPoolSyncHandler
<
SharedDbs
<
FileBackend
>>
,
pubkey
:
PublicKey
,
)
->
KvResult
<
Option
<
duniter_core
::
module
::
TxsHistoryForBma
>>
{
let
duniter_gva_dbs_reader
::
txs_history
::
TxsHistory
{
sending
,
pending
,
..
}
=
dbs_pool
.execute
(
move
|
dbs
|
{
duniter_gva_dbs_reader
::
txs_history
::
get_pending_transactions_for_bma
(
&
dbs
.txs_mp_db
,
pubkey
,
)
})
.expect
(
"dbs pool disconnected"
)
?
;
Ok
(
Some
(
duniter_core
::
module
::
TxsHistoryForBma
{
sent
:
Vec
::
new
(),
received
:
Vec
::
new
(),
sending
,
pending
,
}))
}
// Needed for BMA only
fn
get_tx_by_hash
(
fn
get_tx_by_hash
(
dbs_pool
:
&
fast_threadpool
::
ThreadPoolSyncHandler
<
SharedDbs
<
FileBackend
>>
,
dbs_pool
:
&
fast_threadpool
::
ThreadPoolSyncHandler
<
SharedDbs
<
FileBackend
>>
,
hash
:
Hash
,
hash
:
Hash
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment