Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl App {
View::ChannelDir => {}
}
let mut entries: Vec<(String, BlockRef)> = last_seen.into_iter().collect();
entries.sort_by(|a, b| b.1.cmp(&a.1));
entries.sort_by_key(|(_, at)| std::cmp::Reverse(*at));
entries
.into_iter()
.map(|(ss58, _)| {
Expand Down
21 changes: 18 additions & 3 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tokio_tungstenite::{connect_async, tungstenite::Message as WsMessage};

use crate::error::ChainError;
use crate::event::{ConnState, Event};
use crate::extrinsic::RemarkCallIds;
use crate::reader;
use crate::secret::DecryptionKeys;
use crate::types::Pubkey;
Expand Down Expand Up @@ -128,10 +129,19 @@ pub async fn fetch_and_process_extrinsic(
ext_index: u16,
my_pubkey: Pubkey,
keys: DecryptionKeys,
remark_calls: RemarkCallIds,
tx: Sender<Event>,
) {
let result =
fetch_extrinsic_inner(node_url, block_num, ext_index, &my_pubkey, &keys, &tx).await;
let result = fetch_extrinsic_inner(
node_url,
block_num,
ext_index,
&my_pubkey,
&keys,
remark_calls,
&tx,
)
.await;
if let Err(e) = result {
let _ = tx.send(Event::Error(format!(
"Load block {block_num}:{ext_index}: {e}"
Expand All @@ -145,13 +155,15 @@ async fn fetch_extrinsic_inner(
ext_index: u16,
my_pubkey: &Pubkey,
keys: &DecryptionKeys,
remark_calls: RemarkCallIds,
tx: &Sender<Event>,
) -> Result<(), ChainError> {
let block = fetch_block(node_url, block_num).await?;
if let Some(ext_hex) = block.extrinsics.get(usize::from(ext_index)) {
let ctx = reader::ReadContext {
my_pubkey,
keys,
remark_calls,
tx,
};
reader::read_extrinsic(ext_hex, &ctx, block_num, ext_index, block.timestamp_ms);
Expand Down Expand Up @@ -181,12 +193,13 @@ pub async fn subscribe_blocks(
node_url: &str,
my_pubkey: Pubkey,
keys: DecryptionKeys,
remark_calls: RemarkCallIds,
tx: Sender<Event>,
) {
let mut delay: u32 = 1;
loop {
let _ = tx.send(Event::ConnectionStatus(ConnState::Connected));
match run_subscription(node_url, &my_pubkey, &keys, &tx).await {
match run_subscription(node_url, &my_pubkey, &keys, remark_calls, &tx).await {
Ok(()) => return,
Err(e) => {
let _ = tx.send(Event::Status(format!("Chain disconnected: {e}")));
Expand All @@ -206,6 +219,7 @@ async fn run_subscription(
node_url: &str,
my_pubkey: &Pubkey,
keys: &DecryptionKeys,
remark_calls: RemarkCallIds,
tx: &Sender<Event>,
) -> Result<(), ChainError> {
let (mut ws, _) = connect_async(node_url)
Expand Down Expand Up @@ -267,6 +281,7 @@ async fn run_subscription(
let ctx = reader::ReadContext {
my_pubkey,
keys,
remark_calls,
tx,
};
reader::read_block(block, &ctx);
Expand Down
16 changes: 15 additions & 1 deletion src/chain_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use samp::{GenesisHash, SpecVersion, Ss58Prefix, TxVersion};
use serde::{Deserialize, Serialize};

use crate::error::SdkError;
use crate::extrinsic::ChainInfo;
use crate::extrinsic::{ChainInfo, RemarkCallIds};
use crate::types::ChainName;

// Cached `spec_version`/`tx_version` are never used at sign time:
Expand All @@ -23,6 +23,8 @@ pub struct ChainSnapshot {
pub genesis_hash: [u8; 32],
pub spec_version: u32,
pub tx_version: u32,
pub system_remark_call: Option<[u8; 2]>,
pub system_remark_with_event_call: [u8; 2],
pub account_storage_offset: usize,
pub account_storage_width: usize,
pub errors: Vec<ErrorRecord>,
Expand Down Expand Up @@ -58,6 +60,11 @@ impl ChainSnapshot {
genesis_hash: *info.chain_params.genesis_hash().as_bytes(),
spec_version: info.chain_params.spec_version().get(),
tx_version: info.chain_params.tx_version().get(),
system_remark_call: info.remark_calls.remark.map(|(p, c)| [p, c]),
system_remark_with_event_call: [
info.remark_calls.remark_with_event.0,
info.remark_calls.remark_with_event.1,
],
account_storage_offset: info.account_storage.offset,
account_storage_width: info.account_storage.width,
errors,
Expand Down Expand Up @@ -89,6 +96,13 @@ impl ChainSnapshot {
SpecVersion::new(self.spec_version),
TxVersion::new(self.tx_version),
),
remark_calls: RemarkCallIds {
remark: self.system_remark_call.map(|[p, c]| (p, c)),
remark_with_event: (
self.system_remark_with_event_call[0],
self.system_remark_with_event_call[1],
),
},
account_storage: StorageLayout {
offset: self.account_storage_offset,
width: self.account_storage_width,
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum ChainError {
BadShape,
#[error("metadata: {0}")]
Metadata(#[from] samp::metadata::Error),
#[error("runtime does not expose {0}.{1}")]
RuntimeCallMissing(&'static str, &'static str),
#[error("extrinsic: {0}")]
ExtrinsicBuild(#[from] samp::extrinsic::Error),
#[error("message too long: {len} bytes (max u32::MAX)")]
Expand Down
Loading
Loading