mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
relative time locking improvements
This commit is contained in:
parent
130fea0937
commit
9d15c27bfd
3 changed files with 19 additions and 5 deletions
|
@ -69,6 +69,10 @@ public class Transaction extends TransactionPart {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRelativeLocktimeAllowed() {
|
||||||
|
return version >= 2L;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isReplaceByFee() {
|
public boolean isReplaceByFee() {
|
||||||
if(locktime == 0) return false;
|
if(locktime == 0) return false;
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,10 @@ import java.io.OutputStream;
|
||||||
public class TransactionInput extends TransactionPart {
|
public class TransactionInput extends TransactionPart {
|
||||||
public static final long SEQUENCE_LOCKTIME_DISABLED = 4294967295L;
|
public static final long SEQUENCE_LOCKTIME_DISABLED = 4294967295L;
|
||||||
public static final long SEQUENCE_RBF_ENABLED = 4294967293L;
|
public static final long SEQUENCE_RBF_ENABLED = 4294967293L;
|
||||||
public static final long MAX_RELATIVE_TIMELOCK = 0x40FFFF;
|
public static final long MAX_RELATIVE_TIMELOCK = 2147483647L;
|
||||||
public static final long MAX_RELATIVE_TIMELOCK_IN_BLOCKS = 0xFFFF;
|
public static final long RELATIVE_TIMELOCK_VALUE_MASK = 0xFFFF;
|
||||||
|
public static final long RELATIVE_TIMELOCK_TYPE_FLAG = 0x400000;
|
||||||
|
public static final int RELATIVE_TIMELOCK_SECONDS_INCREMENT = 512;
|
||||||
|
|
||||||
// Allows for altering transactions after they were broadcast. Values below NO_SEQUENCE-1 mean it can be altered.
|
// Allows for altering transactions after they were broadcast. Values below NO_SEQUENCE-1 mean it can be altered.
|
||||||
private long sequence;
|
private long sequence;
|
||||||
|
@ -113,15 +115,19 @@ public class TransactionInput extends TransactionPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRelativeTimeLocked() {
|
public boolean isRelativeTimeLocked() {
|
||||||
return sequence <= MAX_RELATIVE_TIMELOCK;
|
return getTransaction().isRelativeLocktimeAllowed() && sequence <= MAX_RELATIVE_TIMELOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRelativeTimeLockedInBlocks() {
|
public boolean isRelativeTimeLockedInBlocks() {
|
||||||
return sequence <= MAX_RELATIVE_TIMELOCK_IN_BLOCKS;
|
return isRelativeTimeLocked() && ((sequence & RELATIVE_TIMELOCK_TYPE_FLAG) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getRelativeLocktime() {
|
public long getRelativeLocktime() {
|
||||||
return sequence & MAX_RELATIVE_TIMELOCK_IN_BLOCKS;
|
return sequence & RELATIVE_TIMELOCK_VALUE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Transaction getTransaction() {
|
||||||
|
return (Transaction)getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||||
|
|
|
@ -34,6 +34,10 @@ public abstract class TransactionPart {
|
||||||
|
|
||||||
protected abstract void parse() throws ProtocolException;
|
protected abstract void parse() throws ProtocolException;
|
||||||
|
|
||||||
|
public TransactionPart getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
public final void setParent(TransactionPart parent) {
|
public final void setParent(TransactionPart parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue