1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::core::{
error::{OutPointError, TransactionError},
Capacity, Cycle, FeeRate,
};
use crate::packed::Byte32;
use ckb_error::{
impl_error_conversion_with_kind, prelude::*, Error, ErrorKind, InternalError, InternalErrorKind,
};
use std::collections::HashMap;
#[derive(Error, Debug, Clone)]
pub enum Reject {
#[error("The min fee rate is {0} shannons/KB, so the transaction fee should be {1} shannons at least, but only got {2}")]
LowFeeRate(FeeRate, u64, u64),
#[error("Transaction exceeded maximum ancestors count limit, try send it later")]
ExceededMaximumAncestorsCount,
#[error("Transaction pool exceeded maximum {0} limit({1}), try send it later")]
Full(String, u64),
#[error("Transaction({0}) already exist in transaction_pool")]
Duplicated(Byte32),
#[error("Malformed {0} transaction")]
Malformed(String),
#[error("Resolve failed {0}")]
Resolve(OutPointError),
#[error("Verification failed {0}")]
Verification(Error),
}
fn is_malformed_from_verification(error: &Error) -> bool {
match error.kind() {
ErrorKind::Transaction => error
.downcast_ref::<TransactionError>()
.expect("error kind checked")
.is_malformed_tx(),
ErrorKind::Script => true,
ErrorKind::Internal => {
error
.downcast_ref::<InternalError>()
.expect("error kind checked")
.kind()
== InternalErrorKind::CapacityOverflow
}
_ => false,
}
}
impl Reject {
pub fn is_malformed_tx(&self) -> bool {
match self {
Reject::Malformed(_) => true,
Reject::Verification(err) => is_malformed_from_verification(err),
_ => false,
}
}
}
impl_error_conversion_with_kind!(Reject, ErrorKind::SubmitTransaction, Error);
#[derive(Debug, PartialEq, Eq)]
pub enum TxStatus {
Pending,
Proposed,
}
#[derive(Debug, PartialEq, Eq)]
pub struct TxEntryInfo {
pub cycles: Cycle,
pub size: u64,
pub fee: Capacity,
pub ancestors_size: u64,
pub ancestors_cycles: u64,
pub ancestors_count: u64,
}
#[derive(Debug, PartialEq, Eq)]
pub struct TxPoolIds {
pub pending: Vec<Byte32>,
pub proposed: Vec<Byte32>,
}
#[derive(Debug, PartialEq, Eq)]
pub struct TxPoolEntryInfo {
pub pending: HashMap<Byte32, TxEntryInfo>,
pub proposed: HashMap<Byte32, TxEntryInfo>,
}