Transaction: Add methods for calculating transaction weight and virtual transaction size.
@@ -735,4 +735,14 @@ public class TransactionTest {
uint32ToByteStreamLE(getLockTime(), stream);
}
}
+
+ @Test
+ public void getWeightAndVsize() {
+ // example from https://en.bitcoin.it/wiki/Weight_units
+ String txHex = "0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f85603000000171600141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b928ffffffff019caef505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02483045022100f764287d3e99b1474da9bec7f7ed236d6c81e793b20c4b5aa1f3051b9a7daa63022016a198031d5554dbb855bdbe8534776a4be6958bd8d530dc001c32b828f6f0ab0121038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990ac00000000";
+ Transaction tx = new Transaction(UNITTEST, HEX.decode(txHex));
+ assertEquals(218, tx.getMessageSize());
+ assertEquals(542, tx.getWeight());
+ assertEquals(136, tx.getVsize());
+ }
}
