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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
029e9594
Commit
029e9594
authored
Dec 16, 2020
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[feat] gva: add query currentBlock
parent
26e41959
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1347
Feat/gva sub new blocks
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust-libs/modules/gva/gql/src/queries.rs
+2
-0
2 additions, 0 deletions
rust-libs/modules/gva/gql/src/queries.rs
rust-libs/modules/gva/gql/src/queries/current_block.rs
+74
-0
74 additions, 0 deletions
rust-libs/modules/gva/gql/src/queries/current_block.rs
with
76 additions
and
0 deletions
rust-libs/modules/gva/gql/src/queries.rs
+
2
−
0
View file @
029e9594
...
...
@@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub
mod
account_balance
;
pub
mod
current_block
;
pub
mod
current_frame
;
pub
mod
gen_tx
;
pub
mod
txs_history
;
...
...
@@ -27,6 +28,7 @@ use duniter_dbs::databases::cm_v1::CmV1DbReadable as _;
pub
struct
QueryRoot
(
queries
::
NodeQuery
,
queries
::
account_balance
::
AccountBalanceQuery
,
queries
::
current_block
::
CurrentBlockQuery
,
queries
::
current_frame
::
CurrentFrameQuery
,
queries
::
gen_tx
::
GenTxsQuery
,
queries
::
txs_history
::
TxsHistoryBlockchainQuery
,
...
...
This diff is collapsed.
Click to expand it.
rust-libs/modules/gva/gql/src/queries/current_block.rs
0 → 100644
+
74
−
0
View file @
029e9594
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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
crate
::
*
;
#[derive(Default)]
pub
(
crate
)
struct
CurrentBlockQuery
;
#[async_graphql::Object]
impl
CurrentBlockQuery
{
/// Get current block
async
fn
current_block
(
&
self
,
ctx
:
&
async_graphql
::
Context
<
'_
>
,
)
->
async_graphql
::
Result
<
BlockMeta
>
{
let
data
=
ctx
.data
::
<
GvaSchemaData
>
()
?
;
let
dbs_reader
=
data
.dbs_reader
();
if
let
Some
(
current_block_meta
)
=
data
.dbs_pool
.execute
(
move
|
dbs
|
dbs_reader
.get_current_block
(
&
dbs
.cm_db
))
.await
??
.map
(
Into
::
into
)
{
Ok
(
current_block_meta
)
}
else
{
Err
(
async_graphql
::
Error
::
new
(
"no blockchain"
))
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
crate
::
tests
::
*
;
use
duniter_dbs
::
databases
::
cm_v1
::
CmV1Db
;
use
duniter_dbs
::
BlockMetaV2
;
#[tokio::test]
async
fn
query_current_frame
()
->
anyhow
::
Result
<
()
>
{
let
mut
dbs_reader
=
MockDbsReader
::
new
();
dbs_reader
.expect_get_current_block
::
<
CmV1Db
<
MemSingleton
>>
()
.times
(
1
)
.returning
(|
_
|
{
Ok
(
Some
(
BlockMetaV2
{
..
Default
::
default
()
}))
});
let
schema
=
create_schema
(
dbs_reader
)
?
;
assert_eq!
(
exec_graphql_request
(
&
schema
,
r#"{ currentBlock {nonce} }"#
)
.await
?
,
serde_json
::
json!
({
"data"
:
{
"currentBlock"
:
{
"nonce"
:
0
}
}
})
);
Ok
(())
}
}
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
sign in
to comment