forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode.rs
76 lines (67 loc) Β· 1.72 KB
/
decode.rs
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
use {
super::*,
bitcoin::{
absolute::LockTime, consensus::Encodable, opcodes, script, ScriptBuf, Sequence, Transaction,
TxIn, Witness,
},
ord::{subcommand::decode::Output, Inscription},
};
fn transaction() -> Vec<u8> {
let script = script::Builder::new()
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice([])
.push_slice([0, 1, 2, 3])
.push_opcode(opcodes::all::OP_ENDIF)
.into_script();
let mut witness = Witness::new();
witness.push(script);
witness.push([]);
let transaction = Transaction {
version: 0,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness,
}],
output: Vec::new(),
};
let mut buffer = Vec::new();
transaction.consensus_encode(&mut buffer).unwrap();
buffer
}
#[test]
fn from_file() {
assert_eq!(
CommandBuilder::new("decode transaction.bin")
.write("transaction.bin", transaction())
.run_and_deserialize_output::<Output>(),
Output {
inscriptions: vec![Inscription {
body: Some(vec![0, 1, 2, 3]),
content_type: Some(b"text/plain;charset=utf-8".to_vec()),
..Default::default()
}],
}
);
}
#[test]
fn from_stdin() {
assert_eq!(
CommandBuilder::new("decode")
.stdin(transaction())
.run_and_deserialize_output::<Output>(),
Output {
inscriptions: vec![Inscription {
body: Some(vec![0, 1, 2, 3]),
content_type: Some(b"text/plain;charset=utf-8".to_vec()),
..Default::default()
}],
}
);
}