feat(miniprotocols): Implement tx submission client (#220)
* feat(miniprotocols): Implement tx submission client * Match CDDL specs * Fix build errors * Add server implementation for txsubmission Also includes some documentation for how to use both the client and the server * cargo fmt * clippy suggestions clippy pls * Fail explicitly on missing n2c unix socket --------- Co-authored-by: Pi Lanningham <pi@sundaeswap.finance>
This commit is contained in:
parent
e5d8950e9f
commit
6a3679dcda
19 changed files with 785 additions and 355 deletions
|
|
@ -96,10 +96,10 @@ mod tests {
|
|||
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
||||
println!("decoding json block {}", idx + 1);
|
||||
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let (_, block): BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let (_, block): BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let mut datums = jsonl_str.lines();
|
||||
|
||||
|
|
@ -126,10 +126,10 @@ mod tests {
|
|||
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
||||
println!("decoding json block {}", idx + 1);
|
||||
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let (_, block): BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let (_, block): BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let mut scripts = jsonl_str.lines();
|
||||
|
||||
|
|
|
|||
|
|
@ -1618,13 +1618,12 @@ mod tests {
|
|||
|
||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||
println!("decoding test block {}", idx + 1);
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let block: BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let bytes2 =
|
||||
to_vec(block).expect(&format!("error encoding block cbor for file {}", idx));
|
||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
||||
|
||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||
}
|
||||
|
|
@ -1639,13 +1638,13 @@ mod tests {
|
|||
|
||||
for (idx, header_str) in test_headers.iter().enumerate() {
|
||||
println!("decoding test header {}", idx + 1);
|
||||
let bytes = hex::decode(header_str).expect(&format!("bad header file {}", idx));
|
||||
let bytes = hex::decode(header_str).expect(&format!("bad header file {idx}"));
|
||||
|
||||
let header: Header = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let header: Header =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let bytes2 =
|
||||
to_vec(header).expect(&format!("error encoding header cbor for file {}", idx));
|
||||
to_vec(header).expect(&format!("error encoding header cbor for file {idx}"));
|
||||
|
||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -764,13 +764,13 @@ mod tests {
|
|||
|
||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||
println!("decoding test block {}", idx + 1);
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let block: BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let bytes2 = minicbor::to_vec(block)
|
||||
.expect(&format!("error encoding block cbor for file {}", idx));
|
||||
.expect(&format!("error encoding block cbor for file {idx}"));
|
||||
|
||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -833,13 +833,12 @@ mod tests {
|
|||
|
||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||
println!("decoding test block {}", idx + 1);
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let block: BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let bytes2 =
|
||||
to_vec(block).expect(&format!("error encoding block cbor for file {}", idx));
|
||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
||||
|
||||
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
||||
}
|
||||
|
|
@ -862,13 +861,12 @@ mod tests {
|
|||
|
||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||
println!("decoding test block {}", idx + 1);
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {}", idx));
|
||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
||||
|
||||
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
let block: BlockWrapper =
|
||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
||||
|
||||
let bytes2 =
|
||||
to_vec(block).expect(&format!("error encoding block cbor for file {}", idx));
|
||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
||||
|
||||
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
||||
}
|
||||
|
|
@ -880,13 +878,13 @@ mod tests {
|
|||
|
||||
for (idx, str) in subjects.iter().enumerate() {
|
||||
println!("decoding test header {}", idx + 1);
|
||||
let bytes = hex::decode(str).expect(&format!("bad header file {}", idx));
|
||||
let bytes = hex::decode(str).expect(&format!("bad header file {idx}"));
|
||||
|
||||
let block: BlockHead = minicbor::decode(&bytes[..])
|
||||
.expect(&format!("error decoding cbor for file {}", idx));
|
||||
|
||||
let bytes2 =
|
||||
to_vec(block).expect(&format!("error encoding header cbor for file {}", idx));
|
||||
to_vec(block).expect(&format!("error encoding header cbor for file {idx}"));
|
||||
|
||||
assert_eq!(bytes, bytes2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue