Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
fd6d2218
Commit
fd6d2218
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[mod]gva:bca: req PrepareSimplePayment give block_ref before fork window
parent
a5a9a44a
No related branches found
No related tags found
1 merge request
!1364
Bca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust-libs/modules/gva/bca/src/exec_req_type/prepare_simple_payment.rs
+27
-4
27 additions, 4 deletions
...dules/gva/bca/src/exec_req_type/prepare_simple_payment.rs
rust-libs/modules/gva/bca/src/lib.rs
+2
-1
2 additions, 1 deletion
rust-libs/modules/gva/bca/src/lib.rs
with
29 additions
and
5 deletions
rust-libs/modules/gva/bca/src/exec_req_type/prepare_simple_payment.rs
+
27
−
4
View file @
fd6d2218
...
...
@@ -25,11 +25,21 @@ pub(super) async fn exec_req_prepare_simple_payment(
let
issuer
=
params
.issuer
;
let
dbs_reader
=
bca_executor
.dbs_reader
();
let
(
amount
,
current_block
,
(
inputs
,
inputs_sum
))
=
bca_executor
let
(
amount
,
block_ref_number
,
block_ref_hash
,
(
inputs
,
inputs_sum
))
=
bca_executor
.dbs_pool
.execute
(
move
|
dbs
|
{
if
let
Some
(
current_block
)
=
dbs_reader
.get_current_block_meta
(
&
dbs
.cm_db
)
?
{
let
block_ref_number
=
if
current_block
.number
<
101
{
0
}
else
{
current_block
.number
-
101
};
let
block_ref_hash
=
dbs_reader
.block
(
&
dbs
.bc_db_ro
,
U32BE
(
block_ref_number
))
?
.expect
(
"unreachable"
)
.hash
;
let
current_base
=
current_block
.unit_base
as
i64
;
if
amount
.base
()
>
current_base
{
Err
(
"too long base"
.into
())
}
else
{
...
...
@@ -38,7 +48,8 @@ pub(super) async fn exec_req_prepare_simple_payment(
}
Ok
::
<
_
,
ExecReqTypeError
>
((
amount
,
current_block
,
block_ref_number
,
block_ref_hash
,
dbs_reader
.find_inputs
(
&
dbs
.bc_db_ro
,
&
dbs
.txs_mp_db
,
...
...
@@ -60,8 +71,8 @@ pub(super) async fn exec_req_prepare_simple_payment(
Ok
(
BcaRespTypeV0
::
PrepareSimplePayment
(
PrepareSimplePaymentResp
{
current_block_number
:
current_block
.
number
,
current_block_hash
:
current_block
.
hash
,
current_block_number
:
block_ref_
number
,
current_block_hash
:
block_ref_
hash
,
inputs
,
inputs_sum
,
},
...
...
@@ -101,6 +112,10 @@ mod tests {
.expect_get_current_block_meta
::
<
CmV1Db
<
MemSingleton
>>
()
.times
(
1
)
.returning
(|
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
dbs_reader
.expect_block
()
.times
(
1
)
.returning
(|
_
,
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
let
bca_executor
=
create_bca_executor
(
dbs_reader
)
.expect
(
"fail to create bca executor"
);
let
resp_res
=
exec_req_prepare_simple_payment
(
...
...
@@ -122,6 +137,10 @@ mod tests {
.expect_get_current_block_meta
::
<
CmV1Db
<
MemSingleton
>>
()
.times
(
1
)
.returning
(|
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
dbs_reader
.expect_block
()
.times
(
1
)
.returning
(|
_
,
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
dbs_reader
.expect_find_inputs
::
<
BcV2DbRo
<
FileBackend
>
,
TxsMpV2Db
<
FileBackend
>>
()
.times
(
1
)
...
...
@@ -158,6 +177,10 @@ mod tests {
.expect_get_current_block_meta
::
<
CmV1Db
<
MemSingleton
>>
()
.times
(
1
)
.returning
(|
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
dbs_reader
.expect_block
()
.times
(
1
)
.returning
(|
_
,
_
|
Ok
(
Some
(
BlockMetaV2
::
default
())));
dbs_reader
.expect_find_inputs
::
<
BcV2DbRo
<
FileBackend
>
,
TxsMpV2Db
<
FileBackend
>>
()
.times
(
1
)
...
...
This diff is collapsed.
Click to expand it.
rust-libs/modules/gva/bca/src/lib.rs
+
2
−
1
View file @
fd6d2218
...
...
@@ -35,6 +35,7 @@ use dubp::crypto::keys::{ed25519::Ed25519KeyPair, Signator};
use
duniter_bca_types
::{
bincode_opts
,
BcaReq
,
BcaReqExecError
,
BcaReqTypeV0
,
BcaResp
,
BcaRespTypeV0
,
BcaRespV0
,
};
pub
use
duniter_dbs
::
kv_typed
::
prelude
::
*
;
use
duniter_dbs
::{
FileBackend
,
SharedDbs
};
use
futures
::{
prelude
::
stream
::
FuturesUnordered
,
StreamExt
,
TryStream
,
TryStreamExt
};
use
once_cell
::
sync
::
OnceCell
;
...
...
@@ -222,12 +223,12 @@ mod tests {
pub
use
duniter_dbs
::
databases
::
bc_v2
::{
BcV2DbReadable
,
BcV2DbRo
};
pub
use
duniter_dbs
::
databases
::
cm_v1
::{
CmV1Db
,
CmV1DbReadable
};
pub
use
duniter_dbs
::
databases
::
txs_mp_v2
::{
TxsMpV2Db
,
TxsMpV2DbReadable
};
pub
use
duniter_dbs
::
kv_typed
::
prelude
::
*
;
pub
use
duniter_dbs
::
BlockMetaV2
;
pub
use
futures
::
TryStreamExt
;
mockall
::
mock!
{
pub
DbsReader
{
fn
block
(
&
self
,
bc_db
:
&
BcV2DbRo
<
FileBackend
>
,
number
:
U32BE
)
->
KvResult
<
Option
<
BlockMetaV2
>>
;
fn
find_inputs
<
BcDb
:
'static
+
BcV2DbReadable
,
TxsMpDb
:
'static
+
TxsMpV2DbReadable
>
(
&
self
,
bc_db
:
&
BcDb
,
...
...
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