3
0
mirror of https://github.com/Qortal/AT.git synced 2025-01-30 19:02:14 +00:00

More visibility tightening. Bump to v1.3.3 due to some method signature changes.

This commit is contained in:
catbref 2020-04-09 12:59:23 +01:00
parent 6e9198b226
commit d9338f31d3
10 changed files with 101 additions and 103 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.ciyam</groupId> <groupId>org.ciyam</groupId>
<artifactId>AT</artifactId> <artifactId>AT</artifactId>
<version>1.3.2</version> <version>1.3.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<skipTests>true</skipTests> <skipTests>true</skipTests>

View File

@ -152,44 +152,98 @@ public abstract class API {
/* Convenience methods to allow subclasses to access package-scoped a1-a4, b1-b4 variables */ /* Convenience methods to allow subclasses to access package-scoped a1-a4, b1-b4 variables */
public void zeroA(MachineState state) { protected long getA1(MachineState state) {
return state.a1;
}
protected long getA2(MachineState state) {
return state.a2;
}
protected long getA3(MachineState state) {
return state.a3;
}
protected long getA4(MachineState state) {
return state.a4;
}
protected byte[] getA(MachineState state) {
ByteBuffer byteBuffer = ByteBuffer.allocate(4 * 8);
byteBuffer.putLong(state.a1);
byteBuffer.putLong(state.a2);
byteBuffer.putLong(state.a3);
byteBuffer.putLong(state.a4);
return byteBuffer.array();
}
protected long getB1(MachineState state) {
return state.b1;
}
protected long getB2(MachineState state) {
return state.b2;
}
protected long getB3(MachineState state) {
return state.b3;
}
protected long getB4(MachineState state) {
return state.b4;
}
protected byte[] getB(MachineState state) {
ByteBuffer byteBuffer = ByteBuffer.allocate(4 * 8);
byteBuffer.putLong(state.b1);
byteBuffer.putLong(state.b2);
byteBuffer.putLong(state.b3);
byteBuffer.putLong(state.b4);
return byteBuffer.array();
}
protected void zeroA(MachineState state) {
state.a1 = 0L; state.a1 = 0L;
state.a2 = 0L; state.a2 = 0L;
state.a3 = 0L; state.a3 = 0L;
state.a4 = 0L; state.a4 = 0L;
} }
public void zeroB(MachineState state) { protected void zeroB(MachineState state) {
state.b1 = 0L; state.b1 = 0L;
state.b2 = 0L; state.b2 = 0L;
state.b3 = 0L; state.b3 = 0L;
state.b4 = 0L; state.b4 = 0L;
} }
public void setAToMaxValue(MachineState state) { protected void setAToMaxValue(MachineState state) {
state.a1 = 0xffffffffffffffffL; state.a1 = 0xffffffffffffffffL;
state.a2 = 0xffffffffffffffffL; state.a2 = 0xffffffffffffffffL;
state.a3 = 0xffffffffffffffffL; state.a3 = 0xffffffffffffffffL;
state.a4 = 0xffffffffffffffffL; state.a4 = 0xffffffffffffffffL;
} }
public void setA1(MachineState state, long value) { protected void setA1(MachineState state, long value) {
state.a1 = value; state.a1 = value;
} }
public void setA2(MachineState state, long value) { protected void setA2(MachineState state, long value) {
state.a2 = value; state.a2 = value;
} }
public void setA3(MachineState state, long value) { protected void setA3(MachineState state, long value) {
state.a3 = value; state.a3 = value;
} }
public void setA4(MachineState state, long value) { protected void setA4(MachineState state, long value) {
state.a4 = value; state.a4 = value;
} }
public void setA(MachineState state, byte[] bytes) { protected void setA(MachineState state, byte[] bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
state.a1 = byteBuffer.getLong(); state.a1 = byteBuffer.getLong();
@ -198,23 +252,23 @@ public abstract class API {
state.a4 = byteBuffer.getLong(); state.a4 = byteBuffer.getLong();
} }
public void setB1(MachineState state, long value) { protected void setB1(MachineState state, long value) {
state.b1 = value; state.b1 = value;
} }
public void setB2(MachineState state, long value) { protected void setB2(MachineState state, long value) {
state.b2 = value; state.b2 = value;
} }
public void setB3(MachineState state, long value) { protected void setB3(MachineState state, long value) {
state.b3 = value; state.b3 = value;
} }
public void setB4(MachineState state, long value) { protected void setB4(MachineState state, long value) {
state.b4 = value; state.b4 = value;
} }
public void setB(MachineState state, byte[] bytes) { protected void setB(MachineState state, byte[] bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
state.b1 = byteBuffer.getLong(); state.b1 = byteBuffer.getLong();

View File

@ -329,60 +329,6 @@ public class MachineState {
this.hadFatalError = hadFatalError; this.hadFatalError = hadFatalError;
} }
public long getA1() {
return this.a1;
}
public long getA2() {
return this.a2;
}
public long getA3() {
return this.a3;
}
public long getA4() {
return this.a4;
}
public byte[] getA() {
ByteBuffer byteBuffer = ByteBuffer.allocate(4 * 8);
byteBuffer.putLong(this.a1);
byteBuffer.putLong(this.a2);
byteBuffer.putLong(this.a3);
byteBuffer.putLong(this.a4);
return byteBuffer.array();
}
public long getB1() {
return this.b1;
}
public long getB2() {
return this.b2;
}
public long getB3() {
return this.b3;
}
public long getB4() {
return this.b4;
}
public byte[] getB() {
ByteBuffer byteBuffer = ByteBuffer.allocate(4 * 8);
byteBuffer.putLong(this.b1);
byteBuffer.putLong(this.b2);
byteBuffer.putLong(this.b3);
byteBuffer.putLong(this.b4);
return byteBuffer.array();
}
public int getCurrentBlockHeight() { public int getCurrentBlockHeight() {
return this.currentBlockHeight; return this.currentBlockHeight;
} }

View File

@ -2,7 +2,7 @@ package org.ciyam.at;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public enum OpCodeParam { enum OpCodeParam {
VALUE { VALUE {
@Override @Override

View File

@ -100,10 +100,7 @@ public class Timestamp {
* @return CIYAM-AT "timestamp" as long * @return CIYAM-AT "timestamp" as long
*/ */
public static long toLong(int blockHeight, int transactionSequence) { public static long toLong(int blockHeight, int transactionSequence) {
long longValue = ((long) blockHeight) << 32; return toLong(blockHeight, NATIVE_BLOCKCHAIN_ID, transactionSequence);
// NOP: longValue |= ((long) NATIVE_BLOCKCHAIN_ID) << 24;
longValue |= transactionSequence;
return longValue;
} }
} }

View File

@ -1,6 +1,7 @@
package org.ciyam.at; package org.ciyam.at;
public interface TwoValueComparator { @FunctionalInterface
interface TwoValueComparator {
public boolean compare(long a, long b); public boolean compare(long a, long b);

View File

@ -1,6 +1,7 @@
package org.ciyam.at; package org.ciyam.at;
public interface TwoValueOperator { @FunctionalInterface
interface TwoValueOperator {
public long apply(long a, long b); public long apply(long a, long b);

View File

@ -3,7 +3,7 @@ package org.ciyam.at;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class Utils { interface Utils {
/** /**
* Returns immediate function code enum from code bytes at current position. * Returns immediate function code enum from code bytes at current position.
@ -11,11 +11,11 @@ public class Utils {
* Initial position is <tt>codeByteBuffer.position()</tt> but on return is incremented by 2. * Initial position is <tt>codeByteBuffer.position()</tt> but on return is incremented by 2.
* *
* @param codeByteBuffer * @param codeByteBuffer
* @return FunctionCode enum * @return FunctionCode
* @throws CodeSegmentException * @throws CodeSegmentException if we ran out of bytes trying to fetch raw function code value
* @throws InvalidAddressException * @throws IllegalFunctionCodeException if we can't convert raw function code to FunctionCode object
*/ */
public static FunctionCode getFunctionCode(ByteBuffer codeByteBuffer) throws CodeSegmentException, IllegalFunctionCodeException { static FunctionCode getFunctionCode(ByteBuffer codeByteBuffer) throws CodeSegmentException, IllegalFunctionCodeException {
try { try {
int rawFunctionCode = codeByteBuffer.getShort(); int rawFunctionCode = codeByteBuffer.getShort();
@ -38,11 +38,11 @@ public class Utils {
* <b>Note:</b> address is not scaled by <tt>Constants.VALUE_SIZE</tt> unlike other methods in this class. * <b>Note:</b> address is not scaled by <tt>Constants.VALUE_SIZE</tt> unlike other methods in this class.
* *
* @param codeByteBuffer * @param codeByteBuffer
* @return int address into code bytes * @return int address into code segment
* @throws CodeSegmentException * @throws CodeSegmentException if we ran out of bytes trying to fetch code address
* @throws InvalidAddressException * @throws InvalidAddressException if fetched address points outside of code segment
*/ */
public static int getCodeAddress(ByteBuffer codeByteBuffer) throws CodeSegmentException, InvalidAddressException { static int getCodeAddress(ByteBuffer codeByteBuffer) throws CodeSegmentException, InvalidAddressException {
try { try {
int address = codeByteBuffer.getInt(); int address = codeByteBuffer.getInt();
@ -63,11 +63,11 @@ public class Utils {
* <b>Note:</b> address is returned scaled by <tt>Constants.VALUE_SIZE</tt>. * <b>Note:</b> address is returned scaled by <tt>Constants.VALUE_SIZE</tt>.
* *
* @param codeByteBuffer * @param codeByteBuffer
* @return int address into data bytes * @return int address into data segment
* @throws CodeSegmentException * @throws CodeSegmentException if we ran out of bytes trying to fetch data address
* @throws InvalidAddressException * @throws InvalidAddressException if fetched address points outside of data segment
*/ */
public static int getDataAddress(ByteBuffer codeByteBuffer, ByteBuffer dataByteBuffer) throws CodeSegmentException, InvalidAddressException { static int getDataAddress(ByteBuffer codeByteBuffer, ByteBuffer dataByteBuffer) throws CodeSegmentException, InvalidAddressException {
try { try {
int address = codeByteBuffer.getInt() * MachineState.VALUE_SIZE; int address = codeByteBuffer.getInt() * MachineState.VALUE_SIZE;
@ -89,17 +89,17 @@ public class Utils {
* *
* @param codeByteBuffer * @param codeByteBuffer
* @return byte offset * @return byte offset
* @throws CodeSegmentException * @throws CodeSegmentException if we ran out of bytes trying to fetch offset
* @throws InvalidAddressException * @throws InvalidAddressException if position + offset is outside of code segment
*/ */
public static byte getCodeOffset(ByteBuffer codeByteBuffer) throws CodeSegmentException, InvalidAddressException { static byte getCodeOffset(ByteBuffer codeByteBuffer) throws CodeSegmentException, InvalidAddressException {
try { try {
final byte offset = codeByteBuffer.get(); final byte offset = codeByteBuffer.get();
final int target = codeByteBuffer.position() + offset; final int target = codeByteBuffer.position() + offset;
if (target < 0 || target >= codeByteBuffer.limit() - 1) if (target < 0 || target >= codeByteBuffer.limit())
throw new InvalidAddressException(String.format("Code target PC+%02x=[%04x] out of bounds: 0x0000 to 0x%04x", throw new InvalidAddressException(String.format("Code target PC(%04x) + %02x = %04x out of bounds: 0x0000 to 0x%04x",
codeByteBuffer.position() - 1, offset, target, codeByteBuffer.limit() - 1 -1)); codeByteBuffer.position() - 1, offset, target, codeByteBuffer.limit() - 1));
return offset; return offset;
} catch (BufferUnderflowException e) { } catch (BufferUnderflowException e) {
@ -114,10 +114,9 @@ public class Utils {
* *
* @param codeByteBuffer * @param codeByteBuffer
* @return long value * @return long value
* @throws CodeSegmentException * @throws CodeSegmentException if we ran out of bytes trying to fetch value
* @throws InvalidAddressException
*/ */
public static long getCodeValue(ByteBuffer codeByteBuffer) throws CodeSegmentException, InvalidAddressException { static long getCodeValue(ByteBuffer codeByteBuffer) throws CodeSegmentException {
try { try {
return codeByteBuffer.getLong(); return codeByteBuffer.getLong();
} catch (BufferUnderflowException e) { } catch (BufferUnderflowException e) {

View File

@ -101,7 +101,7 @@ public class BlockchainFunctionCodeTests extends ExecutableTest {
byte[] expectedBlockHash = api.blockchain.get(previousBlockHeight - 1).blockHash; byte[] expectedBlockHash = api.blockchain.get(previousBlockHeight - 1).blockHash;
byte[] aBytes = state.getA(); byte[] aBytes = api.getA(state);
assertTrue("Block hash mismatch", Arrays.equals(expectedBlockHash, aBytes)); assertTrue("Block hash mismatch", Arrays.equals(expectedBlockHash, aBytes));
assertTrue(state.getIsFinished()); assertTrue(state.getIsFinished());

View File

@ -304,7 +304,7 @@ public class TestAPI extends API {
} }
public TestTransaction getTransactionFromA(MachineState state) { public TestTransaction getTransactionFromA(MachineState state) {
byte[] aBytes = state.getA(); byte[] aBytes = this.getA(state);
String txHashString = stringifyHash(aBytes); String txHashString = stringifyHash(aBytes);
return transactions.get(txHashString); return transactions.get(txHashString);
} }
@ -346,7 +346,7 @@ public class TestAPI extends API {
System.out.println("generateRandomUsingTransactionInA: second call - returning random"); System.out.println("generateRandomUsingTransactionInA: second call - returning random");
// HASH(A and new block hash) // HASH(A and new block hash)
return (state.getA1() ^ 9L) << 3 ^ (state.getA2() ^ 9L) << 12 ^ (state.getA3() ^ 9L) << 5 ^ (state.getA4() ^ 9L); return (this.getA1(state) ^ 9L) << 3 ^ (this.getA2(state) ^ 9L) << 12 ^ (this.getA3(state) ^ 9L) << 5 ^ (this.getA4(state) ^ 9L);
} }
} }
@ -385,7 +385,7 @@ public class TestAPI extends API {
@Override @Override
public void payAmountToB(long amount, MachineState state) { public void payAmountToB(long amount, MachineState state) {
byte[] bBytes = state.getB(); byte[] bBytes = this.getB(state);
String address = decodeAddress(bBytes); String address = decodeAddress(bBytes);
TestAccount recipient = accounts.get(address); TestAccount recipient = accounts.get(address);
@ -402,14 +402,14 @@ public class TestAPI extends API {
@Override @Override
public void messageAToB(MachineState state) { public void messageAToB(MachineState state) {
byte[] bBytes = state.getB(); byte[] bBytes = this.getB(state);
String address = decodeAddress(bBytes); String address = decodeAddress(bBytes);
TestAccount recipient = accounts.get(address); TestAccount recipient = accounts.get(address);
if (recipient == null) if (recipient == null)
throw new IllegalStateException("Refusing to send message to unknown account: " + address); throw new IllegalStateException("Refusing to send message to unknown account: " + address);
recipient.messages.add(state.getA()); recipient.messages.add(this.getA(state));
} }
@Override @Override