forked from dcdpr/libtxref-java
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTxrefDecodingExample.java
55 lines (43 loc) · 1.97 KB
/
TxrefDecodingExample.java
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
package design.contract.example;
import design.contract.txref.DecodedResult;
import design.contract.txref.Txref;
public class TxrefDecodingExample {
/**
* Decode a simple txref for a mainnet transaction
*/
private static void decodeStandardTxref() {
DecodedResult decodedResult = Txref.decode("tx1:r52q-qqpq-qpty-cfg");
assert(decodedResult.getBlockHeight() == 170);
assert(decodedResult.getTransactionIndex() == 1);
assert(decodedResult.getTxoIndex() == 0);
assert(decodedResult.getEncoding() == DecodedResult.Encoding.BECH32M);
}
/**
* Decode an extended txref for a mainnet transaction
*/
private static void decodeExtendedTxref() {
DecodedResult decodedResult = Txref.decode("tx1:y52q-qqpq-qpqq-4lkz-zc");
assert(decodedResult.getBlockHeight() == 170);
assert(decodedResult.getTransactionIndex() == 1);
assert(decodedResult.getTxoIndex() == 1);
assert(decodedResult.getEncoding() == DecodedResult.Encoding.BECH32M);
}
/**
* Decode a simple txref--however, this txref has been encoded with the original bech32 internal
* constant. The decoding will still succeed, but the library will also return a commentary string
* that contains an explanatory message along with the txref that should be used instead.
*/
private static void decodeStandardTxrefUsingOriginalConstant() {
DecodedResult decodedResult = Txref.decode("tx1:r52q-qqpq-q5h5-5v2");
assert(decodedResult.getBlockHeight() == 170);
assert(decodedResult.getTransactionIndex() == 1);
assert(decodedResult.getTxoIndex() == 0);
assert(decodedResult.getEncoding() == DecodedResult.Encoding.BECH32);
assert(decodedResult.getCommentary().contains("tx1:r52q-qqpq-qpty-cfg"));
}
public static void main(String[] args) {
decodeStandardTxref();
decodeExtendedTxref();
decodeStandardTxrefUsingOriginalConstant();
}
}