Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli-v2s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
Rust
Ğcli-v2s
Merge requests
!49
Draft: Nostr
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
Draft: Nostr
nostr
into
master
Overview
0
Commits
7
Pipelines
8
Changes
2
Open
poka
requested to merge
nostr
into
master
1 month ago
Overview
0
Commits
7
Pipelines
8
Changes
2
0
0
Merge request reports
Viewing commit
dfcc91f2
Prev
Next
Show latest version
2 files
+
91
−
51
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
dfcc91f2
ok
· dfcc91f2
fred
authored
4 weeks ago
src/indexer.rs
+
89
−
51
View file @ dfcc91f2
Edit in single-file editor
Open in Web IDE
Show full file
@@ -191,59 +191,97 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
let
i_latest_h
=
convert_hash_bytea
(
i_latest_block
.hash
);
let
i_latest_n
=
i_latest_block
.height
;
fn
color
(
x
:
bool
)
->
Color
{
match
x
{
true
=>
Color
::
Green
,
false
=>
Color
::
Red
,
match
data
.args.output_format
{
OutputFormat
::
Json
=>
{
let
output
=
serde_json
::
json!
({
"duniter"
:
{
"url"
:
d_url
,
"genesis_hash"
:
d_gen_hash
,
"finalized_block"
:
{
"number"
:
d_finalized_n
,
"hash"
:
d_finalized_h
.to_string
()
},
"latest_block"
:
{
"number"
:
d_latest_n
,
"hash"
:
d_latest_h
.to_string
()
}
},
"indexer"
:
{
"url"
:
i_url
,
"genesis_hash"
:
i_gen_hash
,
"finalized_block"
:
{
"number"
:
i_finalized_n
,
"hash"
:
i_finalized_h
.map
(|
h
|
h
.to_string
())
},
"latest_block"
:
{
"number"
:
i_latest_n
,
"hash"
:
i_latest_h
.to_string
()
}
},
"status"
:
{
"genesis_hash_match"
:
d_gen_hash
==
i_gen_hash
,
"finalized_block_match"
:
i_finalized_h
.map_or
(
false
,
|
h
|
h
==
d_finalized_h
),
"latest_block_match"
:
i_latest_n
==
d_latest_n
as
i64
&&
i_latest_h
==
d_latest_h
}
});
println!
(
"{}"
,
serde_json
::
to_string_pretty
(
&
output
)
.unwrap
());
},
OutputFormat
::
Human
=>
{
fn
color
(
x
:
bool
)
->
Color
{
match
x
{
true
=>
Color
::
Green
,
false
=>
Color
::
Red
,
}
}
let
mut
table
=
Table
::
new
();
table
.load_preset
(
presets
::
UTF8_FULL
)
.apply_modifier
(
modifiers
::
UTF8_ROUND_CORNERS
)
.set_content_arrangement
(
ContentArrangement
::
Dynamic
)
.set_width
(
120
)
.set_header
(
vec!
[
"Variable"
,
"Duniter"
,
"Indexer"
])
.add_row
(
vec!
[
"URL"
,
d_url
,
i_url
])
.add_row
(
vec!
[
Cell
::
new
(
"genesis hash"
),
Cell
::
new
(
d_gen_hash
),
Cell
::
new
(
i_gen_hash
)
.fg
(
color
(
d_gen_hash
==
i_gen_hash
)),
])
.add_row
(
vec!
[
Cell
::
new
(
"finalized block number"
),
Cell
::
new
(
d_finalized_n
),
match
i_finalized_n
{
None
=>
Cell
::
new
(
"not indexed"
)
.fg
(
Color
::
Yellow
),
Some
(
n
)
=>
{
// if it exists, it must be the same
assert_eq!
(
n
,
d_finalized_n
as
i64
);
Cell
::
new
(
""
)
}
},
])
.add_row
(
vec!
[
Cell
::
new
(
"finalized block hash"
),
Cell
::
new
(
d_finalized_h
),
match
i_finalized_h
{
// number already tells it is not indexed
None
=>
Cell
::
new
(
""
),
Some
(
h
)
=>
Cell
::
new
(
h
)
.fg
(
color
(
h
==
d_finalized_h
)),
},
])
.add_row
(
vec!
[
Cell
::
new
(
"latest block number"
),
Cell
::
new
(
d_latest_n
),
Cell
::
new
(
i_latest_n
)
.fg
(
color
(
i_latest_n
==
d_latest_n
as
i64
)),
])
.add_row
(
vec!
[
Cell
::
new
(
"latest block hash"
),
Cell
::
new
(
d_latest_h
),
Cell
::
new
(
i_latest_h
)
.fg
(
color
(
i_latest_h
==
d_latest_h
)),
]);
println!
(
"{table}"
);
}
}
let
mut
table
=
Table
::
new
();
table
.load_preset
(
presets
::
UTF8_FULL
)
.apply_modifier
(
modifiers
::
UTF8_ROUND_CORNERS
)
.set_content_arrangement
(
ContentArrangement
::
Dynamic
)
.set_width
(
120
)
.set_header
(
vec!
[
"Variable"
,
"Duniter"
,
"Indexer"
])
.add_row
(
vec!
[
"URL"
,
d_url
,
i_url
])
.add_row
(
vec!
[
Cell
::
new
(
"genesis hash"
),
Cell
::
new
(
d_gen_hash
),
Cell
::
new
(
i_gen_hash
)
.fg
(
color
(
d_gen_hash
==
i_gen_hash
)),
])
.add_row
(
vec!
[
Cell
::
new
(
"finalized block number"
),
Cell
::
new
(
d_finalized_n
),
match
i_finalized_n
{
None
=>
Cell
::
new
(
"not indexed"
)
.fg
(
Color
::
Yellow
),
Some
(
n
)
=>
{
// if it exists, it must be the same
assert_eq!
(
n
,
d_finalized_n
as
i64
);
Cell
::
new
(
""
)
}
},
])
.add_row
(
vec!
[
Cell
::
new
(
"finalized block hash"
),
Cell
::
new
(
d_finalized_h
),
match
i_finalized_h
{
// number already tells it is not indexed
None
=>
Cell
::
new
(
""
),
Some
(
h
)
=>
Cell
::
new
(
h
)
.fg
(
color
(
h
==
d_finalized_h
)),
},
])
.add_row
(
vec!
[
Cell
::
new
(
"latest block number"
),
Cell
::
new
(
d_latest_n
),
Cell
::
new
(
i_latest_n
)
.fg
(
color
(
i_latest_n
==
d_latest_n
as
i64
)),
])
.add_row
(
vec!
[
Cell
::
new
(
"latest block hash"
),
Cell
::
new
(
d_latest_h
),
Cell
::
new
(
i_latest_h
)
.fg
(
color
(
i_latest_h
==
d_latest_h
)),
]);
println!
(
"{table}"
);
}
};
Loading