Skip to content

Commit

Permalink
add refHeight in Transaction class
Browse files Browse the repository at this point in the history
  • Loading branch information
neetpill committed Jan 2, 2015
1 parent c7e0e6d commit 8c27b56
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/src/main/java/com/google/bitcoin/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public int compare(final Transaction tx1, final Transaction tx2) {
private ArrayList<TransactionOutput> outputs;

private long lockTime;
private long refHeight;

// This is either the time the transaction was broadcast as measured from the local clock, or the time from the
// block in which it was included. Note that this can be changed by re-orgs so the wallet may update this field.
Expand Down Expand Up @@ -511,7 +512,7 @@ protected static int calcLength(byte[] buf, int offset) {
cursor += scriptLen + varint.getOriginalSizeInBytes();
}
// 4 = length of lock_time field (uint32)
return cursor - offset + 4;
return cursor - offset + 4 + 4;
}

void parse() throws ProtocolException {
Expand Down Expand Up @@ -547,7 +548,8 @@ void parse() throws ProtocolException {
cursor += scriptLen;
}
lockTime = readUint32();
optimalEncodingMessageSize += 4;
refHeight = readUint32();
optimalEncodingMessageSize += 4 + 4;
length = cursor - offset;
}

Expand Down Expand Up @@ -1083,6 +1085,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
for (TransactionOutput out : outputs)
out.bitcoinSerialize(stream);
uint32ToByteStreamLE(lockTime, stream);
uint32ToByteStreamLE(refHeight, stream);
}


Expand All @@ -1109,6 +1112,18 @@ public void setLockTime(long lockTime) {
this.lockTime = lockTime;
}

/** returns reference height **/
public long getRefHeight() {
maybeParse();
return refHeight;
}

/** sets reference height **/
public void setRefHeight(long refHeight) {
unCache();
this.refHeight = refHeight;
}

/**
* @return the version
*/
Expand Down

0 comments on commit 8c27b56

Please sign in to comment.