Add getSignatureStatus

This commit is contained in:
Michael Vines
2018-09-26 17:12:40 -07:00
parent a23c230603
commit 1821e72812
2 changed files with 60 additions and 16 deletions

View File

@@ -84,6 +84,14 @@ pub struct Meta {
}
impl Metadata for Meta {}
#[derive(PartialEq, Serialize)]
pub enum RpcSignatureStatus {
Confirmed,
SignatureNotFound,
ProgramRuntimeError,
GenericFailure,
}
build_rpc_trait! {
pub trait RpcSol {
type Metadata;
@@ -103,6 +111,9 @@ build_rpc_trait! {
#[rpc(meta, name = "getLastId")]
fn get_last_id(&self, Self::Metadata) -> Result<String>;
#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(&self, Self::Metadata, String) -> Result<RpcSignatureStatus>;
#[rpc(meta, name = "getTransactionCount")]
fn get_transaction_count(&self, Self::Metadata) -> Result<u64>;
@@ -119,17 +130,10 @@ impl RpcSol for RpcSolImpl {
type Metadata = Meta;
fn confirm_transaction(&self, meta: Self::Metadata, id: String) -> Result<bool> {
let signature_vec = bs58::decode(id)
.into_vec()
.map_err(|_| Error::invalid_request())?;
if signature_vec.len() != mem::size_of::<Signature>() {
return Err(Error::invalid_request());
}
let signature = Signature::new(&signature_vec);
meta.request_processor
.get_signature_status(signature)
.map(|res| res.is_ok())
self.get_signature_status(meta, id)
.map(|status| status == RpcSignatureStatus::Confirmed)
}
fn get_account_info(&self, meta: Self::Metadata, id: String) -> Result<Account> {
let pubkey_vec = bs58::decode(id)
.into_vec()
@@ -156,6 +160,23 @@ impl RpcSol for RpcSolImpl {
fn get_last_id(&self, meta: Self::Metadata) -> Result<String> {
meta.request_processor.get_last_id()
}
fn get_signature_status(&self, meta: Self::Metadata, id: String) -> Result<RpcSignatureStatus> {
let signature_vec = bs58::decode(id)
.into_vec()
.map_err(|_| Error::invalid_request())?;
if signature_vec.len() != mem::size_of::<Signature>() {
return Err(Error::invalid_request());
}
let signature = Signature::new(&signature_vec);
Ok(
match meta.request_processor.get_signature_status(signature) {
Ok(_) => RpcSignatureStatus::Confirmed,
Err(BankError::ProgramRuntimeError) => RpcSignatureStatus::ProgramRuntimeError,
Err(BankError::SignatureNotFound) => RpcSignatureStatus::SignatureNotFound,
Err(_) => RpcSignatureStatus::GenericFailure,
},
)
}
fn get_transaction_count(&self, meta: Self::Metadata) -> Result<u64> {
meta.request_processor.get_transaction_count()
}
@@ -172,10 +193,7 @@ impl RpcSol for RpcSolImpl {
let now = Instant::now();
let mut signature_status;
loop {
signature_status = meta
.request_processor
.get_signature_status(signature)
.map_err(|_| Error::internal_error())?;
signature_status = meta.request_processor.get_signature_status(signature);
if signature_status.is_ok() {
return Ok(bs58::encode(signature).into_string());
@@ -227,8 +245,8 @@ impl JsonRpcRequestProcessor {
let id = self.bank.last_id();
Ok(bs58::encode(id).into_string())
}
fn get_signature_status(&self, signature: Signature) -> Result<result::Result<(), BankError>> {
Ok(self.bank.get_signature_status(&signature))
fn get_signature_status(&self, signature: Signature) -> result::Result<(), BankError> {
self.bank.get_signature_status(&signature)
}
fn get_transaction_count(&self) -> Result<u64> {
Ok(self.bank.transaction_count() as u64)