Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Wallet
bitcoinj
Commits
9aae88f4
Commit
9aae88f4
authored
May 23, 2018
by
T Dev. D
😎
Browse files
add weight & vsize calculation
parent
3fbce801
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
core/src/main/java/org/bitcoinj/core/Transaction.java
core/src/main/java/org/bitcoinj/core/Transaction.java
+41
-0
No files found.
core/src/main/java/org/bitcoinj/core/Transaction.java
View file @
9aae88f4
...
...
@@ -189,6 +189,11 @@ public class Transaction extends ChildMessage {
@Nullable
private
String
memo
;
/**
* Segwit makes sigop limit four times higher and scales regular sigops by four.
*/
public
static
final
int
WITNESS_SCALE_FACTOR
=
4
;
public
Transaction
(
NetworkParameters
params
)
{
super
(
params
);
version
=
1
;
...
...
@@ -1688,4 +1693,40 @@ public class Transaction extends ChildMessage {
public
void
setMemo
(
String
memo
)
{
this
.
memo
=
memo
;
}
/**
* Transaction weight is a segwit-related computation 3b+t where b is the size of a transaction serialized in the
* traditional manner without witness data, and t is the size of a transaction serialized in the segwit format
* with witness data.
*/
public
int
getWeight
()
{
final
int
baseLength
;
{
final
ByteArrayOutputStream
base
=
new
UnsafeByteArrayOutputStream
(
length
<
32
?
32
:
length
+
32
);
try
{
bitcoinSerializeToStream
(
base
,
TransactionOptions
.
NONE
);
}
catch
(
IOException
e
)
{
;
// Cannot happen, we are serializing to a memory stream
}
baseLength
=
base
.
size
();
}
final
int
totalLength
;
{
final
ByteArrayOutputStream
total
=
new
UnsafeByteArrayOutputStream
(
length
<
32
?
32
:
length
+
32
);
try
{
bitcoinSerializeToStream
(
total
,
TransactionOptions
.
WITNESS
);
}
catch
(
IOException
e
)
{
;
// Cannot happen, we are serializing to a memory stream
}
totalLength
=
total
.
size
();
}
return
baseLength
*
(
WITNESS_SCALE_FACTOR
-
1
)
+
totalLength
;
}
public
int
getVirtualTransactionSize
()
{
return
(
getWeight
()
+
WITNESS_SCALE_FACTOR
-
1
)
/
WITNESS_SCALE_FACTOR
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment