3
0
mirror of https://github.com/Qortal/AT.git synced 2025-01-30 10:52:14 +00:00
Commit Graph

15 Commits

Author SHA1 Message Date
catbref
18f679e6eb MachineState's initial previousBalance is set to AT's balance at deployment 2020-04-07 17:00:01 +01:00
catbref
d22e16e033 Improve comments in FunctionCode.java 2020-04-07 16:58:21 +01:00
catbref
36c63b0be0 Improved testing.
Rolled the superior blockchain simulating parts from ACCTAPI into
TestAPI.

Tried to replace literal test values with named constants from TestAPI
class, or derived values.

Added some more opcode tests to cover more cases.

Renamed some functions of the form "put something ... in A" to
"put something .. into A" to help distinguish them from
"get ... based on something in A".

Added {GET,SET}_[AB]_IND functions as an addition to the long-winded
GET_A1..A4, SET_B1..B4.

Added more function code tests and separated those tests out into 3
different test classes for manageability.

Possible logic error in PAY_TO_ADDRESS_IN_B and PAY_PREVIOUS_TO_ADDRESS_IN_B
but needs testing!

Improved comments.
2020-04-06 17:37:00 +01:00
catbref
92281a1d04 Conversion to big-endian. Hashing functions use 2 data, not A.
Conversion to big-endian to allow reuse of hash output without
having to swap endian. e.g. saving output of HASH160 into data
segment, and then hashing more of data segment to produce P2SH address.

Also changed hashing functions to fetch data start address and data
byte length from data segment, rather than loading values into A.

Tidied up some tests.
Remove obsolete ACCT test.
2020-03-09 13:29:34 +00:00
catbref
36029c132f Changed FunctionCodes that perform hashes to use variable-length data.
Before, hashing functions (e.g. MD5_A_INTO_B) would hash immediate
data stored in A, putting the result into B.

Also, that hash function would only hash the same number of bits as
the hash output. For example, MD5_A_INTO_B would only hash the
16 bytes in A1 & A2.

Now, hash functions use data-page offset stored in A1 and byte-length
stored in A2.

Renamed HASH160 to RMD160 and created new HASH160 which performs
Bitcoin's double hash of RMD160(SHA256(data)).

Refactored & added tests to cover.
2020-02-28 17:11:53 +00:00
catbref
9a6b49970e Fix typo 2020-02-28 17:11:40 +00:00
catbref
436a65c281 Fix wrong operator when calculating creationBytesLength 2019-11-21 17:28:49 +00:00
catbref
00fd8b040d Updated for Java 11 & other improvements
API:
Added sample AT-emitted transaction types (payment/message).
Maximum number of steps per execution round no longer hard-coded.
API.putTransactionAfterTimestampInA() sets A to zero if no more transactions.
API.putMessageFromTransactionInAIntoB sets B to zero if not a message transaction.
Added some convenience methods.

MachineState:
Added support for minimum activation amount.
Added static method for packing AT into "creation bytes".
No need to store unchanging code in per-height AT state data.

Added support for multiple blockchains to "Timestamp".

General improvements based on Sonarlint suggestions.
General improvements to comments.
Replaced deprecated Byte/Short/Integer/Long constructor call with corresponding .valueOf() call.
Replaced some string concatenations with StringBuilder.

Moved Java-related .gitignore from root to /Java/

Removed .classpath and .project, and added same to .gitignore

Added info on how to add CIYAM AT JAR to other projects.

Updated pom.xml:
Bumped version to 1.2
Bumped Java version from 1.8 to 11
Bumped BouncyCastle from 1.60 to 1.64

Added more tests.
2019-11-20 11:06:57 +00:00
catbref
297ccbdaf6 Added support for execution steps/fees.
Two new API calls:
    getOpCodeSteps(OpCode) : int
    getFeePerStep() : long
This allows API to determine cost per "step" and charge more for (say) function opcodes.

MachineState knows the balance at the end of each execution round,
so now AT's previousBalance is managed by MachineState and added to serialized data.

API calls payCurrentBalanceToB and payPreviousBalanceToB are absorbed into payAmountToB,
and amounts passed are calculated by FunctionCode instead.

Added API call onFinished(long amount, MachineState state) for when AT has finished
so API can return remaining funds (amount) to creator.

Added API call isFirstOpCodeAfterSleeping() : boolean to replace dodgy test of
state.getSteps() == 0 in getRandomUsingTransactionInA().

The API call getCurrentBalance is now used by MachineState to find out AT's balance
at the beginning of execution round. After this, MachineState manages the balance until
the end of execution, whereby the caller can find out the new balance from MachineState.
Corrected some code in FunctionCode to get current balance from MachineState instead in
light of above. (Ditto previousBalance).

Added MAX_STEPS to MachineState to ATs can be made to sleep if they execute too many
steps in one execution round.

Added some pre-execution checks to MachineState.execute() to prevent execution in some
cases, like already finished, or not enough balance to un-freeze, or not reached
required block while sleeping, etc.

Unit tests pass, but there are no test for new steps/fee code yet!
2018-10-12 17:25:10 +01:00
catbref
454d4bed35 OpCode refactoring, versioned constants, refactored tests
API is now an abstract class instead of an Interface. This is to
allow protected methods that give access to package-scoped methods
and variables inside MachineState.

MachineState now supports a different set of constants based on AT
version.

MachineState's methods and variables have had their scopes tightened
up and getters/setters added where appropriate.

MachineState.parseHeader() inlined into the constructor that calls it
so it can set public final variables.

Some reordering and additional comments in MachineState.

OpCode enum entries refactored so that:
a) variables provided via MachineState "state" are not explicitly
passed as well

b) args to each opcode are pre-fetched from the codeByteBuffer before
calling and only need to be cast before use. this comes almost
"for free" thanks to OpCodeParam.fetch

Calling functions from OpCode now cleaner as there's no write-access
to programCounter, only changing codeByteBuffer's position.

Also in OpCode, state.getProgramCounter() now provides a consistent
before-opcode position for branches, jumps, etc.

Lots of repeated code refactored out of unit tests into ExecutableTest
class. ExecutableTest also provides helper methods for examining
post-execution data values, stack positions and entries.
2018-10-05 15:56:32 +01:00
catbref
f0e031599d Initial upload of Java re-implementation
Note that this is unfinished, requiring fee-per-opcode support
and some refactoring.
2018-09-27 13:59:43 +01:00
Ian Knowles
2d7555be98
Merge pull request #2 from spebern/master
correct test 3 output for bor dat
2018-08-26 07:44:53 +00:00
bold
b7aa79d00d correct test 3 output for bor dat 2018-08-26 15:11:59 +08:00
Ian Knowles
2e8cf285d3 Initial documentation added. 2016-02-15 00:44:59 +08:00
Ian Knowles
c7a515ef5e Initial commit 2016-02-15 00:34:00 +08:00