ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
ATs can create AT-Transactions which contain payments (of any asset) and/or messages.
Legacy Qora1 DeployATTransactions create AT records in the repository but set to "finished"
so that they never execute.
More repository support for ATs.
In HSQLDB, create a new TYPE called ATStateHash which is used to verify the same AT outcome
on a per-block basis.
Added Accounts.account as a foreign key to AccountBalances with ON DELETE CASCADE.
ATStates now include state_hash and fees on a per-block basis.
ATTransactions now include asset_id.
When transforming DeployATTransactions, don't include any signature when collating bytes for signing!
CHANGED: added dependency to javax.mail for because of strange "java.lang.NoClassDefFoundError: javax/mail/internet/MimeMultipart" exception when serializing data objects in API resources.
NB: we're still using HSQLDB svn r5836
Updated README.md
Added log4j2.properties file for logging!
Imported CIYAM-AT jar into project-local Maven repo
CIYAM-AT related:
ATData
ATStateData
ATTransactionData
DeployATTransactionData
AT
DeployATTransaction
ATRepository
HSQLDBATRepository
HSQLDBDeployATTransactionRepository
ATTests
DeployATTransactionTransformer
Fixed Block so correct block hash and timestamps are generated,
especially when previous/next block versions differ.
Added extra call in BlockTransformer to aid this.
Fixed GenesisTransaction.isValid's incorrect amount test.
Fixed comments in TransferAssetTransaction and incorrect use of BlockChain.getVotingReleaseTimestamp()
instead of BlockChain.getAssetsReleaseTimestamp().
Added new TYPEs to HSQLDBDatabaseUpdates, and set LOB granularity to 1KB for AT use.
Added AT_address column to DeployATTransactions in HSQLDB.
Added ATs, ATStates and ATTransactions tables.
(You will need to discard existing database and rebuild).
Fixed incorrect byte array output in IssueAssetTransactionTransformer,
where Asset "references" were not processed correctly.
Added support for BigDecimal serialization to a byte-array size other than the standard 8.
FIXED: save ApiClient.translator
CHANGED: ApiClient now respects more resource annotations for building help messages (success and error responses)
CHANGED: Added more detailed annotations to BlocksResource
Some payments don't always initialize the recipient's
last reference, depending on whether the asset is QORA or not and
what type of transaction is being processed.
Calls to Payment.process/orphan now take boolean to indicate
whether recipient's last reference should always be initialized
regardless of asset.
("initialized" here means setting an initial last reference for
an account if the current value is null/empty/missing)
When matching orders to produce trades, it isn't enough to only
sort orders with best price first. Orders with the same price also
need to be further sorted by earliest order first. (This was
implicitly done in Qora v1). Added additional ORDER BY sub-clause
to achieve this and improved the corresponding table index too.
Converted a lot of logging from simplistic System.out/err.println
to Apache log4j2. Added several "trace"-level logging statements
to aid debugging which can be activated given appropriate
configuration in log4j2.properties.
With voting, detection of previous votes was broken during orphan
as previousOptionIndex was set to 0 instead of null when fetching
a VoteOnPollTransaction from the HSQLDB repository. This was due
to lack of null-checking - now fixed.
Corresponding changes made in IssueAsset and Message
transaction HSQLDB repository classes.
v1feeder now syncs up to block 99055. Block 99056 contains DeployAT.
Orphaning back to block 1 and then resync works without issue too.
HSQLDB v2.4.0 had some issue with non-padded, case-insensitive string comparisons.
This is fixed in svn r5836-ish of HSQLDB but yet to be pushed out to new HSQLDB release.
So this commit includes hsqldb-r5836.jar and modified pom.xml/.classpath for now.
No need for duplicate, hidden creatorPublicKey in CancelOrderTransactionData,
CreateOrderTransactionData and CreatePollTransactionData.
Various changes to use more try-with-resources, especially with JDBC objects like
Connection, Statement, PreparedStatement, ResultSet.
Added loads of missing @Override annotations.
Fixed bug in Asset exchange order matching where the matching logic loop
would incorrectly adjust temporary amount fulfilled
by the "want" asset amount (in matchedAmount)
instead of the "have" asset amount (in tradePrice).
Disabled check for duplicate asset name in IssueAssetTransactions for old v1 transactions.
In HSQLDB repository we now use ResultSet.getTimestamp(index, UTC-calendar) to make sure we
only store/fetch UTC timestamps. The UTC-calendar is made using static final TimeZone called
HSQLDBRepository.UTC.
To keep asset IDs in line with v1, Assets.asset_id values are generated on-the-fly in HSQLDB
using a "before insert" trigger on Assets table. Corresponding code
calling HSQLDBRepository.callIdentity() replaced with SELECT statement instead.
Moved most of the HSQLDB connection properties from the connection URL to explicit code in
HSQLDBRepositoryFactory.
Fixed incorrect 'amount' lengths in PaymentTransformer, as used by MultiPayment and Arbitrary
transaction types.
Added support for mangled arbitrary transaction bytes when generating/verifying a v1 transaction signature.
In v1 Arbitrary transactions, bytes-for-signing are lost prior to final payment (but only if there are any payments).
Added corresponding code for multi-payment transactions in the same vein.
NOTE: requires HSQLDB built from svn rev 5836 or later
Fixed BuyNameTransactionData constructors not picking up nameReference.
Added new "orphan" tool to regress blockchain back to specified block.
Added new Block constructor for when receiving a block from the network.
Fixed Block generatingBalance/forging code to be compliant with v1.
Added logging of transactions that fail validation during block validation.
Fixed buyer/seller balances not being updated during name purchase.
Generally replace BigDecimal.compareTo expressions with "<operator> 0" form.
e.g. instead of someBigDecimal.compareTo(anotherBigDecimal) == 1
we now have someBigDecimal.compareTo(anotherBigDecimal) > 0
Fix amounts involved in BuyNameTransactions.
Renamed Transaction.calcSignature to .sign
Refactored Transaction.toBytesLessSignature to TransactionTransformer.toBytesForSigning,
which itself calls subclass' toBytesForSigningImpl,
which might override Transaction.toBytesForSigningImpl when special v1 mangling is required.
Corrected more cases of NTP.getTime in transaction processing
which should really be transaction's timestmap instead.
Fixed HSQLDB-related issue where strings were padded with spaces during comparison.
Some column types no longer case-insensitive as that mode of comparison
is done during transaction validation.
Added missing option_index column to CreatePollTransactionOptions which was causing
out-of-order options during fetching from repository and hence signature failures.
Added unit tests for v1-special mangled transaction signature checking.
Removed checks for remaining bytes to ByteBuffer in various transaction transformers'
fromByteBuffer() methods as the buffer underflow exception is now caught in
TransactionTransformer.fromBytes.
Corrected byte-related transformations of CreatePollTransactions that were missing
voter counts (albeit always zero).
Corrected byte-related transformations of IssueAssetTransactions that were missing
duplicate signature/reference (v1-special).
Added "txhex" tool to output transaction in hex form, given base58 tx signature.
Added "v1feeder" tool to fetch blocks from v1 node and process them.
Added isFulfilled property to asset orders so completed orders can be filtered out.
Fixed migrate app by adding dummy name_reference values to UpdateNameTransactions and BuyNameTransactions INSERTS.
Fixed migrate app to use "poll_name" instead of "poll" for column name. Ditto "option_name" instead of "option".
Fixed some other incorrect column names in HSQLDBAssetRepository.
More unit tests but probably need yet more to cover complicated asset order matching with various divisibility settings.
Maybe fuzzing would help here somehow?
Settings class reworked to allow easier testing
Fix to Payment.orphan() where fee was being incorrectly subtracted instead of added
Added AssetRepository.fromAssetName(String): AssetData
Fixed deleting assets from HSQLDB repository due to broken column name in SQL.
Fixed saving IssueAssetTransactions in HSQLDB repository due to missing column binding.
More TransactionTests!
Fixed IssueAssetTransactions not being constructed with signature.
Fixed incorrect MessageTransactionData constructors.
Refactored various transactions to remove duplicate code.
e.g. in CancelOrderTransaction.process() use getCreator() instead of explicit repository call.
Added name_reference to BuyNameTransactions HSQLDB table.
Fixed incorrect SQL in HSQLDBMultiPaymentTransactionRepository.
More unit tests!
Fixed wrong data length in CancelOrderTransactionTransformer.
Fixed wrong data length in CreateOrderTransactionTransformer.
Fixed missing payment bytes in MultiPaymentTransactionTransformer.toBytes();
* Added more columns/properties to NameData to support updating timestamps, name sales
and reference to last transaction that changed Name (for orphaning support).
* Fixed serialization/deserialization bugs in MessageTransactions
* More tests
* Added simple genesis block timestamp setting to help testing
* Fixed setting account's last reference
* Moved some Poll constants from CreatePollTransaction to Poll
* HSQLDB: added TYPE PollOptionIndex
* HSQLDB: added previous_option_index to VoteOnPollTransactions table to help orphaning
* HSQLDB: renamed "poll" to "poll_name" in same table
* HSQLDB: PollOptions now has additional option_index column
* Improved TransactionTests to allow for different genesis block timestamps.
* Also added VoteOnPollTransaction test
Added CreatePollTransactionData constructor that doesn't need signature (for creating new transactions).
Added missing "published" timestamp support to PollData and Poll.
Removed extraneous timestamp test from Block.isValid.
Corrected inconsistent column names in poll-related tables in HSQLDBDatabaseUpdates.
HSQLDBRepository.checkedExecute(PreparedStatement) now takes extra Object... params
so that values can be bound to placeholders. Code moved from checkedExecute(String, Object...).
This fixes an issue with exists(String, String, Object...) where placeholders weren't having
any values bound to them. (Also removed "ORDER BY NULL" clause which isn't supported by HSQLDB).
HSQLDBVotingRepository method stubs fleshed out with real code.
TransactionTests rejigged but more work needed to test various transactions before/after their feature
release. e.g. testing create poll transactions before & after they supposedly went live.
Could do with a GenesisBlock constructor that takes a timestamp for testing purposes?
CreatePollTransactionTransformer now skips serializing a null signature,
in the same way PaymentTransactionTransformer does, to aid getBytesLessSignature().
This will probably need to be rolled out to all other transaction types.
* Replaced occurances of "this.repository.getResultSetBytes(resultSet.getBinaryStream(index))"
with "resultSet.getBytes(index)"
* Replaced corresponding preparedStatement.setBinaryStream() with preparedStatement.setBytes()
* Fixed migrate app so DB can be rebuilt using old v1 Qora client
* Moved Asset issue/deissue code from IssueAssetTransaction to Asset business object.
* Added more constructors for Asset using IssueAssetTransactionData or assetId.
* Moved some constants from transaction transfers to business objects (e.g. IssueAssetTransaction)
(They might now make more sense being in Asset)
* Changed some transaction isValid() checks to use transaction's timestamp instead of NTP.getTime()
* New VotingRepository - as yet unimplemented
Really need to rewrite "migrate" and add a ton of unit tests.
* Add implementation for Account.getBalance(assetId, numberOfConfirmations)
* Added orphan() code to Block (CIYAM AT not yet supported)
* Added getOrder() 'navigation' method to CreateOrderTransaction
* Added missing transaction-type cases to various switches in Transaction, transformers, repositories, etc.
* Various repository delete() methods added
* Added save/delete support for transaction types that include payments, like multipayment and arbitrary
* Changed "recipient" in HSQLDB SharedTransactionPayments from QoraPublicKey to QoraAddress
* Code added for calculating an account's generating balance. (CIYAM AT support yet to be added).
* Added associated code in Block for calculating next block's timestamp, generating balance, base target, etc.
* ValidationResult enum added to Block, mostly to aid debugging.
* Block.isValid() now returns ValidationResult instead of boolean.
* Block.isValid() now has added proof-of-stake tests.
* Some blockchain-related constants, like feature release heights/timestamps, moved from Block to BlockChain.
* Added better Block constructor for use when creating a new block.
* Added helpful 'navigation' methods to Block to get to block's parent (or child).
* Changed visibility of block's individual signature calculators to protected, in favour of public sign() method.
* Added asset existence check to Payment.isValid.
* All current transaction objects (qora.transaction.*) now have private subclassed transaction variable to save multiple casts in various methods.
* Also added to above:
* isInvolved(Account) : boolean
* getRecipients() : List<Account>
* getAmount(Account) : BigDecimal
* Added BlockRepository.getLastBlock() to fetch highest block in blockchain.
* Added diagnostics to HSQLDBRepository.close() to alert if there are any uncommitted changes during closure.
(Currently under suspicion due to possible HSQLDB bug!)
* Old "TransactionTests" renamed to "SerializationTests" as that's what they really are.
* New "TransactionTests" added to test processing of transactions. (Currently only a PaymentTransaction).
* PaymentTransformer.toBytes() detects and skips null signature. This was causing issues with Transaction.toBytesLessSignature().
Needs rolling out to other transaction types if acceptable.
* Created PaymentData transfer objects for (recipient, assetId, amount) tuples
* Created corresponding Payment class for validating, processing and orphaning payment(s)
* Modified OrderData to support isClosed for when an Order is cancelled so no more trades can occur
* Migrated CancelOrderTransactions and MultiPaymentTransactions
* Converted MessageTransactions, PaymentTransactions and TransferAssetTransactions to use new Payment class
Can't use PaymentTransformer in PaymentTransformer or TransferAssetTransformer due to serialization differences.
* Added AssetData transfer object
* Added IssueAssetTransactionData transfer object
* Reworked qora.assets.Asset into business layer object
* Reworked qora.transaction.IssueAssetTransaction into business layer object
* Added corresponding AssetRepository and support in TransactionRepository et al
* Fixed BlockChain in line with asset changes
* Some renaming inside GenesisTransaction to reflect use of transfer object, not business object
* Business transaction objects now take Repository param
* Moved HSQLDB transaction repositories into a sub-package
* Changed HSQLDBSaver.execute(Connection connection) to .execute(Repository repository) to fix visibility issues
and allow repository more control in the future if need be
* Changed from "return null" statements in HSQLDB repositories to throw DataException when an error occurs.
Better to throw than to silently return null?
* Added static version of PublicKeyAccount.verify() for when a repository-backed PublicKeyAccount is not needed
* Fixed getter/setter code template incorrectly producing "this.this.field = param"
Moved more repository-like methods from qora.* classes to repository.
Removed qora.block.BlockTransaction as it's pretty much internal to the HSQLDB repository.
Fixing qora.account.*
Fixing genesis-related classes: block, account, transaction...
Rolled BlockTransactionRepository into BlockRepository.
Added AccountRepository for general account info and account balances.
BlockTransformer now takes Block as param instead of BlockData as it needs Block's transactions.
No need for database.DB class as the code is specific to HSQLDB so moved into relevant repository.hsqldb classes.
Top-level Repository instance (e.g. HSQLDBRepository) is used within subclasses, e.g. HSQLDBBlockRepository, so they
can share the same repository state, like underlying SQL Connection for easier transactional support.
HSQLDBRepository subclasses now call checkedExecute() on top-level repository instance, instead of passing Connection
to obsolete DB.checkedExecute.
No need for qora.block.BlockFactory any more as those methods are now in repository.
More work on Blocks and Transactions in general.
Still converting to repository layout.
This commit is just in case my dev computer blows up and also for interim code review.
Removed data.block.BlockData as an interface (with data.block.Block as implementation) for now.
added data access class for block
added HSQLDB repository with reader methods for block data
started usage of repository and data objects in BlockFactory
qora.* packages are business logic/handler/processing
data.* packages are "value objects" or are they "business objects"?
toBytes(), fromBytes() (which used to be called parse()) and toJSON() moved to transform.* packages
new issues:
Lost control of SQL Transactions. Previously, some class "knew" whether to call COMMIT or not.
e.g. simply saving a payment transaction would involve updating Transactions table first, then the PaymentTransactions table after (to satisfy foreign key constraints) then commit.
Processing a block would involve a new transaction, a savepoint, a rollback and then maybe a further commit or rollback.
Not sure how this is going to work with the repository, especially if business logic isn't supposed to be aware of such things.
Growing number of stupid try-catch blocks. Probably best to ditch TransformationException (was ParseException) and throw IllegalStateExceptions instead as they're "unchecked".
What happens if the repository fails to save() to the database? It can't throw SQLException any more as that has no meaning outside the repository. Ditto with delete().
Much tidier code thanks to not having to pass Connection objects around
as params. Also no need for two forms of the same method, one with Connection
param, one without.
Also corrected SQL-Transaction-related methods in DB, e.g. commit, rollback, etc.
so they use the proper underlying JDBC methods.
Use HSQLDB "CREATE TYPE" instead of "CREATE DOMAIN" as collate clause is lost on HSQLDB shutdown in v2.4.0.
Restore GenesisAccount's public key back to 8-byte legacy value.
More work on block/transaction processing.
It's becoming apparent that way too many Connection objects are being passed around, and now with two forms of
methods (one with, one without) it's time to switch to something like thread-local Connections.
Maybe also switch to having data access objects.
So this commit is save work prior to that conversion.
Added Apache commons-net as maven dependency for NTP support.
Added SAVEPOINT and ROLLBACK TO SAVEPOINT support to DB class.
Added exists() test to DB class.
Add MessageTransactions, with V1/V3 code in one class instead of very similar code
split across two classes. Update DB schema to add version.
More fleshing out of Assets class.
Fleshing out Block class with parse(), generating balance and signature-related methods.
More javadoc. More tests.
No need for DB.executeUsingBytes as it was only a specific use-case for DB.checkedExecute.
Callers now refactored to use DB.checkedExecute instead.
Minor tidying up of BlockTransactions in light of above.
In the HSQLDB database, asset keys/IDs are now "asset_id" (previously: "asset").
Added initial Asset/Order/Trade classes.
Added CreateOrderTransaction class.
Renamed some asset-related fields back to old gen1 names, e.g. haveAmount -> amount, wantAmount -> price.
Added Accounts and AccountBalances to database.
Added get/set confirmed balance support to Account.
Added get/set last reference support to Account.
Added Block.toJSON() - untested at this time.
Fleshed out some Transaction sub-classes' process() and orphan() methods.
Fleshed out PaymentTransaction.isValid().
Added Transaction.delete() - untested.
DB.rebuild() to shutdown and delete database, then rebuild it (schema only).
DB.callIdentity() to fetch value of IDENTITY column after an INSERT.
Added basic Asset class.
Added TODOs to Account.
BULK REFACTOR to rename "generation target" back to "generating balance" and
"generation signature" back to "generator signature" to ease compatibility with
old QORA for now. (Maybe change again in the future if we change from PoS).
Added support for Block's totalFees which is either loaded from DB
or recalculated as transactions are added to the block.
Also in Block:
* We can't assume generator's public key is the correct length
in case we encounter the GenesisAccount's special 8-byte public key. Fix applied to
Block's ResultSet-based constructor.
* Forgot to save "signature" column!
* Initial version of Block.process()
* Block constructor takes transactionsSignature too now
Added BlockChain startup/init/validation method to determine whether to (re)build blockchain.
Rebuilding blockchain involves rebuilding DB schema, processing GenesisBlock and adding QORA asset.
Added some initial GenesisTranaction.process() code: GenesisTransactions are saved but recipient's balance/reference not yet updated.
Fix incorrect placeholder bind value for "creation" timestamp in Transaction.save().
Moved incremental database schema updates out from "updates" unit test into DatabaseUpdates class.
All unit tests work at this point!
Add Transaction.parse() support. Subclasses are called, switched by transaction type,
using ByteBuffer.
Correct RECIPIENT_LENGTH in Transaction.
Common [de]serialization tasks moved to methods in Serialization class.
Too many calls needing Connection object in args when they're only
simple database reads. Even worse, some methods had database-less
counterparts with different outputs, e.g. toJSON().
Now Connections can be requested from the pool for general database
read scenarios. Code paths that might perform a multi-statement
database transaction still require a Connection arg passed around
as the database transaction are local to that Connection.
In light of above, added support for database opening, closing,
setting URL.
Fixed out of bounds array index bug in unknown-length version of DB.getResultSetBytes().
Fixed Block's lazy-instantiation of Transactions.
Implemented Block's isSignatureValid().
Fixed bug in Crypto.isValidAddress() which was using the wrong bytes.
Fix GenesisTransaction generic constructor calling super with PaymentTransaction type!
Fix GenesisTransaction signature constructor using wrong column indexes from ResultSet.
In Transaction, don't expect CREATOR_LENGTH bytes from database in case we're dealing
with a GenesisTransaction where the creator's public key is only 8 bytes long.
Improvements to unit tests, including changing migrate so it can be run repeatedly to do
incremental migrations.
PaymentTransaction now uses Account for recipient internally but maybe should extend that type change to constructor args.
GenesisBlock added also with signature test.
More javadocs.
Added brokenmd160.java as command-line support for producing broken MD160 digests.
Transactions, and sub-classes, now use/store public key instead of Qora address.
(Qora address can be derived from public key and they take up about the same space in DB).
Loads more JavaDoc for lovely mouseover help in Eclipse IDE.
Crypto.verify() and Crypto.sign() moved into PublicKeyAccount and PrivateKeyAccount
as appropriate.
Fleshed out Block, added BlockTransactions support.
Added TODO comments as Eclipse helpfully lists these for later implementation.
Made loading-from-DB-constructors protected/private and also throw NoDataFoundException
if unable to load from DB. Public methods can call respective constructors, catch the above
exception and return null if they like. Load-from-DB-constructors are to allow sub-classes
to load some data from sub-tables and super-class to load from another table.
(See PaymentTransaction/Transaction for example). Using public methods allows similar argument
lists but with different names,
e.g. DBObject.fromSignature(Connection, byte[]) and DBObject.fromReference(Connection, byte[])
Saving into DB maybe still a bit untidy. Looking for a way to close-couple column names with
place-holder bind Objects.
Less of:
connection.prepareStatement("INSERT INTO table (column) VALUES (?)")
DB.bindInsertPlaceholders(PreparedStatement, Object...);
More like:
DB.insertUpdate(String tableName, SomeMagicCloseCoupledPairs...)
called like:
DB.insertUpdate("Cats", {"name", "Tiddles"}, {"age", 3});
Most SQL tables defined but only payment transactions actually implemented.
Maven support added.
Some code imported from 'old' Qora:
RIPEMD160 renamed as BrokenMD160 and deprecated.
whispersystem's Ed25519 implementation (to be replaced with bouncycastle).
Basic Account/PublicKeyAccount/PrivateKeyAccount code.
Some utils like Base58 and Pair.
To use:
Use maven to fetch dependencies.
Build project.
Fire up an old-gen Qora node.
Run src/test/update.java as a JUnit test to build DB structure.
Run src/test/migrate.java as a JUnit test to migrate old Qora blocks to DB.
You should now be able to run src/test/load.java and src/test/save.java
as JUnit tests demonstrating loading/saving Transactions from/to database.
This commit done while halfway through adding Block support!