Replace JSON by FlatBuffers
This commit is contained in:
parent
56b8113084
commit
fa009f21b7
16
binding.h
16
binding.h
|
@ -152,6 +152,16 @@ typedef struct CResult_bool {
|
|||
|
||||
#define Backup_VT_UVK 14
|
||||
|
||||
#define RaptorQDrops_VT_DROPS 4
|
||||
|
||||
#define AGEKeys_VT_PK 6
|
||||
|
||||
#define Servers_VT_URLS 4
|
||||
|
||||
#define Progress_VT_TRIAL_DECRYPTIONS 6
|
||||
|
||||
#define Progress_VT_DOWNLOADED 8
|
||||
|
||||
void dummy_export(void);
|
||||
|
||||
void dart_post_cobject(DartPostCObjectFnType ptr);
|
||||
|
@ -284,19 +294,19 @@ struct CResult_____c_char make_payment_uri(uint8_t coin,
|
|||
|
||||
struct CResult_____c_char parse_payment_uri(char *uri);
|
||||
|
||||
struct CResult_____c_char generate_key(void);
|
||||
struct CResult______u8 generate_key(void);
|
||||
|
||||
struct CResult_u8 zip_backup(char *key, char *dst_dir);
|
||||
|
||||
struct CResult_u8 unzip_backup(char *key, char *data_path, char *dst_dir);
|
||||
|
||||
struct CResult_____c_char split_data(uint32_t id, char *data);
|
||||
struct CResult______u8 split_data(uint32_t id, char *data);
|
||||
|
||||
struct CResult_____c_char merge_data(char *drop);
|
||||
|
||||
struct CResult_____c_char get_tx_summary(char *tx);
|
||||
|
||||
struct CResult_____c_char get_best_server(char *servers);
|
||||
struct CResult_____c_char get_best_server(uint8_t *servers, uint64_t len);
|
||||
|
||||
void import_from_zwl(uint8_t coin, char *name, char *data);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::coinconfig::{init_coin, CoinConfig, MEMPOOL, MEMPOOL_RUNNER};
|
||||
use crate::db::data_generated::fb::SendTemplate;
|
||||
use crate::db::data_generated::fb::{ProgressT, SendTemplate, Servers};
|
||||
use crate::db::FullEncryptedBackup;
|
||||
use crate::note_selection::TransactionReport;
|
||||
use crate::{ChainError, TransactionPlan, Tx};
|
||||
|
@ -312,7 +312,16 @@ pub async unsafe extern "C" fn warp(
|
|||
anchor_offset,
|
||||
max_cost,
|
||||
move |progress| {
|
||||
let mut progress = serde_json::to_string(&progress).unwrap().into_dart();
|
||||
let progress = ProgressT {
|
||||
height: progress.height,
|
||||
trial_decryptions: progress.trial_decryptions,
|
||||
downloaded: progress.downloaded as u64,
|
||||
};
|
||||
let mut builder = FlatBufferBuilder::new();
|
||||
let root = progress.pack(&mut builder);
|
||||
builder.finish(root, None);
|
||||
let v = builder.finished_data().to_vec();
|
||||
let mut progress = v.into_dart();
|
||||
if port != 0 {
|
||||
if let Some(p) = POST_COBJ {
|
||||
p(port, &mut progress);
|
||||
|
@ -719,13 +728,15 @@ pub unsafe extern "C" fn parse_payment_uri(uri: *mut c_char) -> CResult<*mut c_c
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn generate_key() -> CResult<*mut c_char> {
|
||||
pub unsafe extern "C" fn generate_key() -> CResult<*const u8> {
|
||||
let res = || {
|
||||
let secret_key = FullEncryptedBackup::generate_key()?;
|
||||
let keys = serde_json::to_string(&secret_key)?;
|
||||
Ok(keys)
|
||||
let mut builder = FlatBufferBuilder::new();
|
||||
let root = secret_key.pack(&mut builder);
|
||||
builder.finish(root, None);
|
||||
Ok(builder.finished_data().to_vec())
|
||||
};
|
||||
to_cresult_str(res())
|
||||
to_cresult_bytes(res())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -765,14 +776,16 @@ pub unsafe extern "C" fn unzip_backup(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn split_data(id: u32, data: *mut c_char) -> CResult<*mut c_char> {
|
||||
pub unsafe extern "C" fn split_data(id: u32, data: *mut c_char) -> CResult<*const u8> {
|
||||
from_c_str!(data);
|
||||
let res = || {
|
||||
let res = crate::fountain::FountainCodes::encode_into_drops(id, &base64::decode(&*data)?)?;
|
||||
let output = serde_json::to_string(&res)?;
|
||||
Ok(output)
|
||||
let mut builder = FlatBufferBuilder::new();
|
||||
let res = res.pack(&mut builder);
|
||||
builder.finish(res, None);
|
||||
Ok(builder.finished_data().to_vec())
|
||||
};
|
||||
to_cresult_str(res())
|
||||
to_cresult_bytes(res())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -802,10 +815,14 @@ pub unsafe extern "C" fn get_tx_summary(tx: *mut c_char) -> CResult<*mut c_char>
|
|||
|
||||
#[tokio::main]
|
||||
#[no_mangle]
|
||||
pub async unsafe extern "C" fn get_best_server(servers: *mut c_char) -> CResult<*mut c_char> {
|
||||
from_c_str!(servers);
|
||||
let best_server = crate::get_best_server(&servers).await;
|
||||
to_cresult_str(best_server)
|
||||
pub async unsafe extern "C" fn get_best_server(servers: *mut u8, len: u64) -> CResult<*mut c_char> {
|
||||
let servers: Vec<u8> = Vec::from_raw_parts(servers, len as usize, len as usize);
|
||||
let res = async {
|
||||
let servers = flatbuffers::root::<Servers>(&servers)?;
|
||||
let best_server = crate::get_best_server(servers).await?;
|
||||
Ok(best_server)
|
||||
};
|
||||
to_cresult_str(res.await)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
13
src/chain.rs
13
src/chain.rs
|
@ -1,3 +1,4 @@
|
|||
use crate::db::data_generated::fb::Servers as fbServers;
|
||||
use crate::db::AccountViewKey;
|
||||
use crate::lw_rpc::compact_tx_streamer_client::CompactTxStreamerClient;
|
||||
use crate::lw_rpc::*;
|
||||
|
@ -8,7 +9,6 @@ use futures::{future, FutureExt};
|
|||
use rand::prelude::SliceRandom;
|
||||
use rand::rngs::OsRng;
|
||||
use rayon::prelude::*;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::marker::PhantomData;
|
||||
|
@ -582,10 +582,10 @@ async fn get_height(server: String) -> Option<(String, u32)> {
|
|||
|
||||
/// Return the URL of the best server given a list of servers
|
||||
/// The best server is the one that has the highest height
|
||||
pub async fn get_best_server(servers: &str) -> anyhow::Result<String> {
|
||||
let servers: Servers = serde_json::from_str(servers)?;
|
||||
pub async fn get_best_server(servers: fbServers<'_>) -> anyhow::Result<String> {
|
||||
let mut server_heights = vec![];
|
||||
for s in servers.urls.iter() {
|
||||
let urls = servers.urls().unwrap();
|
||||
for s in urls.iter() {
|
||||
let server_height =
|
||||
tokio::spawn(timeout(Duration::from_secs(1), get_height(s.to_string()))).boxed();
|
||||
server_heights.push(server_height);
|
||||
|
@ -601,11 +601,6 @@ pub async fn get_best_server(servers: &str) -> anyhow::Result<String> {
|
|||
.ok_or(anyhow::anyhow!("No Lightwalletd"))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Servers {
|
||||
urls: Vec<String>,
|
||||
}
|
||||
|
||||
pub const EXPIRY_HEIGHT_OFFSET: u32 = 50;
|
||||
|
||||
pub fn get_checkpoint_height(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::db::data_generated::fb::AGEKeysT;
|
||||
use age::secrecy::ExposeSecret;
|
||||
use anyhow::anyhow;
|
||||
use rusqlite::backup::Backup;
|
||||
use rusqlite::Connection;
|
||||
use serde::Serialize;
|
||||
use std::fs::File;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -25,11 +25,14 @@ impl FullEncryptedBackup {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn generate_key() -> anyhow::Result<AGEKeys> {
|
||||
pub fn generate_key() -> anyhow::Result<AGEKeysT> {
|
||||
let key = age::x25519::Identity::generate();
|
||||
let sk = key.to_string().expose_secret().clone();
|
||||
let pk = key.to_public().to_string();
|
||||
Ok(AGEKeys { sk, pk })
|
||||
Ok(AGEKeysT {
|
||||
sk: Some(sk),
|
||||
pk: Some(pk),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn add(&mut self, src: &Connection, db_name: &str) -> anyhow::Result<()> {
|
||||
|
@ -104,9 +107,3 @@ impl FullEncryptedBackup {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AGEKeys {
|
||||
pub sk: String,
|
||||
pub pk: String,
|
||||
}
|
||||
|
|
|
@ -4699,5 +4699,594 @@ impl BackupT {
|
|||
})
|
||||
}
|
||||
}
|
||||
pub enum RaptorQDropsOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct RaptorQDrops<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for RaptorQDrops<'a> {
|
||||
type Inner = RaptorQDrops<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RaptorQDrops<'a> {
|
||||
pub const VT_DROPS: flatbuffers::VOffsetT = 4;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
RaptorQDrops { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args RaptorQDropsArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<RaptorQDrops<'bldr>> {
|
||||
let mut builder = RaptorQDropsBuilder::new(_fbb);
|
||||
if let Some(x) = args.drops { builder.add_drops(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> RaptorQDropsT {
|
||||
let drops = self.drops().map(|x| {
|
||||
x.iter().map(|s| s.to_string()).collect()
|
||||
});
|
||||
RaptorQDropsT {
|
||||
drops,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn drops(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(RaptorQDrops::VT_DROPS, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for RaptorQDrops<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<&'_ str>>>>("drops", Self::VT_DROPS, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct RaptorQDropsArgs<'a> {
|
||||
pub drops: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>,
|
||||
}
|
||||
impl<'a> Default for RaptorQDropsArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
RaptorQDropsArgs {
|
||||
drops: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RaptorQDropsBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> RaptorQDropsBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_drops(&mut self, drops: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<&'b str>>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(RaptorQDrops::VT_DROPS, drops);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> RaptorQDropsBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
RaptorQDropsBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<RaptorQDrops<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for RaptorQDrops<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("RaptorQDrops");
|
||||
ds.field("drops", &self.drops());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RaptorQDropsT {
|
||||
pub drops: Option<Vec<String>>,
|
||||
}
|
||||
impl Default for RaptorQDropsT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
drops: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl RaptorQDropsT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<RaptorQDrops<'b>> {
|
||||
let drops = self.drops.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
RaptorQDrops::create(_fbb, &RaptorQDropsArgs{
|
||||
drops,
|
||||
})
|
||||
}
|
||||
}
|
||||
pub enum AGEKeysOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct AGEKeys<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for AGEKeys<'a> {
|
||||
type Inner = AGEKeys<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AGEKeys<'a> {
|
||||
pub const VT_SK: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_PK: flatbuffers::VOffsetT = 6;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
AGEKeys { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args AGEKeysArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<AGEKeys<'bldr>> {
|
||||
let mut builder = AGEKeysBuilder::new(_fbb);
|
||||
if let Some(x) = args.pk { builder.add_pk(x); }
|
||||
if let Some(x) = args.sk { builder.add_sk(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> AGEKeysT {
|
||||
let sk = self.sk().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
let pk = self.pk().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
AGEKeysT {
|
||||
sk,
|
||||
pk,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn sk(&self) -> Option<&'a str> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(AGEKeys::VT_SK, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn pk(&self) -> Option<&'a str> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(AGEKeys::VT_PK, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for AGEKeys<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("sk", Self::VT_SK, false)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("pk", Self::VT_PK, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct AGEKeysArgs<'a> {
|
||||
pub sk: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
pub pk: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
}
|
||||
impl<'a> Default for AGEKeysArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
AGEKeysArgs {
|
||||
sk: None,
|
||||
pk: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AGEKeysBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> AGEKeysBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_sk(&mut self, sk: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(AGEKeys::VT_SK, sk);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_pk(&mut self, pk: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(AGEKeys::VT_PK, pk);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> AGEKeysBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
AGEKeysBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<AGEKeys<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for AGEKeys<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("AGEKeys");
|
||||
ds.field("sk", &self.sk());
|
||||
ds.field("pk", &self.pk());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AGEKeysT {
|
||||
pub sk: Option<String>,
|
||||
pub pk: Option<String>,
|
||||
}
|
||||
impl Default for AGEKeysT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sk: None,
|
||||
pk: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl AGEKeysT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<AGEKeys<'b>> {
|
||||
let sk = self.sk.as_ref().map(|x|{
|
||||
_fbb.create_string(x)
|
||||
});
|
||||
let pk = self.pk.as_ref().map(|x|{
|
||||
_fbb.create_string(x)
|
||||
});
|
||||
AGEKeys::create(_fbb, &AGEKeysArgs{
|
||||
sk,
|
||||
pk,
|
||||
})
|
||||
}
|
||||
}
|
||||
pub enum ServersOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Servers<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Servers<'a> {
|
||||
type Inner = Servers<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Servers<'a> {
|
||||
pub const VT_URLS: flatbuffers::VOffsetT = 4;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Servers { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args ServersArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Servers<'bldr>> {
|
||||
let mut builder = ServersBuilder::new(_fbb);
|
||||
if let Some(x) = args.urls { builder.add_urls(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> ServersT {
|
||||
let urls = self.urls().map(|x| {
|
||||
x.iter().map(|s| s.to_string()).collect()
|
||||
});
|
||||
ServersT {
|
||||
urls,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn urls(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Servers::VT_URLS, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Servers<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<&'_ str>>>>("urls", Self::VT_URLS, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct ServersArgs<'a> {
|
||||
pub urls: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>,
|
||||
}
|
||||
impl<'a> Default for ServersArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
ServersArgs {
|
||||
urls: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ServersBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> ServersBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_urls(&mut self, urls: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<&'b str>>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Servers::VT_URLS, urls);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> ServersBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
ServersBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Servers<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Servers<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Servers");
|
||||
ds.field("urls", &self.urls());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ServersT {
|
||||
pub urls: Option<Vec<String>>,
|
||||
}
|
||||
impl Default for ServersT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
urls: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ServersT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<Servers<'b>> {
|
||||
let urls = self.urls.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
Servers::create(_fbb, &ServersArgs{
|
||||
urls,
|
||||
})
|
||||
}
|
||||
}
|
||||
pub enum ProgressOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Progress<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Progress<'a> {
|
||||
type Inner = Progress<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Progress<'a> {
|
||||
pub const VT_HEIGHT: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_TRIAL_DECRYPTIONS: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_DOWNLOADED: flatbuffers::VOffsetT = 8;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Progress { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args ProgressArgs
|
||||
) -> flatbuffers::WIPOffset<Progress<'bldr>> {
|
||||
let mut builder = ProgressBuilder::new(_fbb);
|
||||
builder.add_downloaded(args.downloaded);
|
||||
builder.add_trial_decryptions(args.trial_decryptions);
|
||||
builder.add_height(args.height);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> ProgressT {
|
||||
let height = self.height();
|
||||
let trial_decryptions = self.trial_decryptions();
|
||||
let downloaded = self.downloaded();
|
||||
ProgressT {
|
||||
height,
|
||||
trial_decryptions,
|
||||
downloaded,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn height(&self) -> u32 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u32>(Progress::VT_HEIGHT, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn trial_decryptions(&self) -> u64 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Progress::VT_TRIAL_DECRYPTIONS, Some(0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn downloaded(&self) -> u64 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<u64>(Progress::VT_DOWNLOADED, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Progress<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<u32>("height", Self::VT_HEIGHT, false)?
|
||||
.visit_field::<u64>("trial_decryptions", Self::VT_TRIAL_DECRYPTIONS, false)?
|
||||
.visit_field::<u64>("downloaded", Self::VT_DOWNLOADED, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct ProgressArgs {
|
||||
pub height: u32,
|
||||
pub trial_decryptions: u64,
|
||||
pub downloaded: u64,
|
||||
}
|
||||
impl<'a> Default for ProgressArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
ProgressArgs {
|
||||
height: 0,
|
||||
trial_decryptions: 0,
|
||||
downloaded: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProgressBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> ProgressBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_height(&mut self, height: u32) {
|
||||
self.fbb_.push_slot::<u32>(Progress::VT_HEIGHT, height, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_trial_decryptions(&mut self, trial_decryptions: u64) {
|
||||
self.fbb_.push_slot::<u64>(Progress::VT_TRIAL_DECRYPTIONS, trial_decryptions, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_downloaded(&mut self, downloaded: u64) {
|
||||
self.fbb_.push_slot::<u64>(Progress::VT_DOWNLOADED, downloaded, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> ProgressBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
ProgressBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Progress<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Progress<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Progress");
|
||||
ds.field("height", &self.height());
|
||||
ds.field("trial_decryptions", &self.trial_decryptions());
|
||||
ds.field("downloaded", &self.downloaded());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ProgressT {
|
||||
pub height: u32,
|
||||
pub trial_decryptions: u64,
|
||||
pub downloaded: u64,
|
||||
}
|
||||
impl Default for ProgressT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
height: 0,
|
||||
trial_decryptions: 0,
|
||||
downloaded: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ProgressT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<Progress<'b>> {
|
||||
let height = self.height;
|
||||
let trial_decryptions = self.trial_decryptions;
|
||||
let downloaded = self.downloaded;
|
||||
Progress::create(_fbb, &ProgressArgs{
|
||||
height,
|
||||
trial_decryptions,
|
||||
downloaded,
|
||||
})
|
||||
}
|
||||
}
|
||||
} // pub mod fb
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::coinconfig::RAPTORQ;
|
||||
use crate::db::data_generated::fb::RaptorQDropsT;
|
||||
use blake2b_simd::Params;
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
|
||||
use raptorq::{Decoder, Encoder, EncodingPacket, ObjectTransmissionInformation};
|
||||
|
@ -26,7 +27,7 @@ impl FountainCodes {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn encode_into_drops(id: u32, data: &[u8]) -> anyhow::Result<RaptorQDrops> {
|
||||
pub fn encode_into_drops(id: u32, data: &[u8]) -> anyhow::Result<RaptorQDropsT> {
|
||||
let total_length = data.len() as u32;
|
||||
let encoder = Encoder::with_defaults(data, QR_DATA_SIZE);
|
||||
let drops: Vec<_> = encoder
|
||||
|
@ -43,7 +44,7 @@ impl FountainCodes {
|
|||
base64::encode(&result)
|
||||
})
|
||||
.collect();
|
||||
Ok(RaptorQDrops { drops })
|
||||
Ok(RaptorQDropsT { drops: Some(drops) })
|
||||
}
|
||||
|
||||
pub fn put_drop(&mut self, drop: &str) -> anyhow::Result<Option<Vec<u8>>> {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::chain::get_latest_height;
|
||||
use crate::db::AccountViewKey;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::chain::{download_chain, DecryptNode};
|
||||
use crate::transaction::get_transaction_details;
|
||||
|
@ -41,7 +40,7 @@ impl std::fmt::Debug for Blocks {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
#[derive(Clone)]
|
||||
pub struct Progress {
|
||||
pub height: u32,
|
||||
pub trial_decryptions: u64,
|
||||
|
|
Loading…
Reference in New Issue