Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Handle errors when an invalid outpoint is requested #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
30 changes: 24 additions & 6 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::io::Read;
use rgb::proof::Proof;
use core::borrow::BorrowMut;
use hyper::method::Method::{Get,Post};
use std::str::FromStr;


struct RGBServer {
Expand All @@ -35,10 +36,14 @@ impl RGBServer {

let parts: Vec<&str> = parts[1].split(":").collect();

Some(OutPoint {
txid: Sha256dHash::from_hex(parts[0]).unwrap(),
vout: parts[1].parse().unwrap()
})
if let Ok(vout) = parts[1].parse() {
Some(OutPoint {
txid: Sha256dHash::from_hex(parts[0]).unwrap(),
vout
})
} else {
None // Could not parse the vout, not an integer
}
}
}

Expand All @@ -50,7 +55,14 @@ impl Handler for RGBServer {
match req.uri {
AbsolutePath(ref path) => {
if req.method == Get {
let outpoint = self.get_outpoint(path).unwrap();
let outpoint = match self.get_outpoint(path) {
Some(val) => val,
None => {
eprintln!("Invalid outpoint in GET req for `{}`", path);
return;
}
};

let proofs = self.database.get_proofs_for(&outpoint);

use bitcoin::network::serialize::RawEncoder;
Expand All @@ -66,7 +78,13 @@ impl Handler for RGBServer {

return;
} else if req.method == Post {
let outpoint = self.get_outpoint(path).unwrap();
let outpoint = match self.get_outpoint(path) {
Some(val) => val,
None => {
eprintln!("Invalid outpoint in POST req for `{}`", path);
return;
}
};

use bitcoin::network::serialize::deserialize;
let decoded: Proof = deserialize(&mut buffer).unwrap();
Expand Down