Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import java.io.BufferedReader;
|
2018-08-02 09:02:33 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import java.math.BigDecimal;
|
2018-08-02 09:02:33 +00:00
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.Socket;
|
|
|
|
import java.net.SocketException;
|
|
|
|
import java.net.SocketTimeoutException;
|
|
|
|
import java.nio.BufferUnderflowException;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.charset.Charset;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2018-08-02 09:02:33 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import java.util.HashMap;
|
2018-08-02 09:02:33 +00:00
|
|
|
import java.util.List;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import java.util.Map;
|
2018-08-02 09:02:33 +00:00
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import org.json.simple.JSONArray;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
import org.json.simple.JSONValue;
|
|
|
|
import org.json.simple.parser.ParseException;
|
2018-08-08 16:02:41 +00:00
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import com.google.common.hash.HashCode;
|
|
|
|
import com.google.common.primitives.Bytes;
|
2018-08-02 09:02:33 +00:00
|
|
|
import com.google.common.primitives.Ints;
|
|
|
|
|
2018-12-12 12:13:06 +00:00
|
|
|
import controller.Controller;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import data.at.ATData;
|
|
|
|
import data.at.ATStateData;
|
2018-08-02 09:02:33 +00:00
|
|
|
import data.block.BlockData;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import data.transaction.ATTransactionData;
|
2018-08-02 09:02:33 +00:00
|
|
|
import data.transaction.TransactionData;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import qora.assets.Asset;
|
2018-08-02 09:02:33 +00:00
|
|
|
import qora.block.Block;
|
|
|
|
import qora.block.Block.ValidationResult;
|
|
|
|
import qora.block.BlockChain;
|
|
|
|
import qora.crypto.Crypto;
|
|
|
|
import repository.DataException;
|
|
|
|
import repository.Repository;
|
2018-12-04 16:34:55 +00:00
|
|
|
import repository.RepositoryFactory;
|
2018-08-02 09:02:33 +00:00
|
|
|
import repository.RepositoryManager;
|
2018-12-04 16:34:55 +00:00
|
|
|
import repository.hsqldb.HSQLDBRepositoryFactory;
|
2018-08-02 09:02:33 +00:00
|
|
|
import transform.TransformationException;
|
|
|
|
import transform.block.BlockTransformer;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import transform.transaction.ATTransactionTransformer;
|
|
|
|
import utils.Base58;
|
2018-08-02 09:02:33 +00:00
|
|
|
import utils.Pair;
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
import utils.Triple;
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
public class v1feeder extends Thread {
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger(v1feeder.class);
|
|
|
|
|
2018-08-02 09:02:33 +00:00
|
|
|
private static final int INACTIVITY_TIMEOUT = 60 * 1000; // milliseconds
|
|
|
|
private static final int CONNECTION_TIMEOUT = 2 * 1000; // milliseconds
|
|
|
|
private static final int PING_INTERVAL = 10 * 1000; // milliseconds
|
|
|
|
private static final int DEFAULT_PORT = 9084;
|
|
|
|
|
|
|
|
private static final int MAGIC_LENGTH = 4;
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
// private static final int TYPE_LENGTH = 4;
|
2018-08-02 09:02:33 +00:00
|
|
|
private static final int HAS_ID_LENGTH = 1;
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
// private static final int ID_LENGTH = 4;
|
|
|
|
// private static final int DATA_SIZE_LENGTH = 4;
|
2018-08-02 09:02:33 +00:00
|
|
|
private static final int CHECKSUM_LENGTH = 4;
|
|
|
|
|
|
|
|
private static final int SIGNATURE_LENGTH = 128;
|
|
|
|
|
|
|
|
private static final byte[] MAINNET_MAGIC = { 0x12, 0x34, 0x56, 0x78 };
|
|
|
|
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
// private static final int GET_PEERS_TYPE = 1;
|
|
|
|
// private static final int PEERS_TYPE = 2;
|
2018-08-02 09:02:33 +00:00
|
|
|
private static final int HEIGHT_TYPE = 3;
|
|
|
|
private static final int GET_SIGNATURES_TYPE = 4;
|
|
|
|
private static final int SIGNATURES_TYPE = 5;
|
|
|
|
private static final int GET_BLOCK_TYPE = 6;
|
|
|
|
private static final int BLOCK_TYPE = 7;
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
// private static final int TRANSACTION_TYPE = 8;
|
2018-08-02 09:02:33 +00:00
|
|
|
private static final int PING_TYPE = 9;
|
|
|
|
private static final int VERSION_TYPE = 10;
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
// private static final int FIND_MYSELF_TYPE = 11;
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
private Socket socket;
|
|
|
|
private OutputStream out;
|
|
|
|
|
|
|
|
private static final int IDLE_STATE = 0;
|
|
|
|
private static final int AWAITING_HEADERS_STATE = 1;
|
|
|
|
private static final int HAVE_HEADERS_STATE = 2;
|
|
|
|
private static final int AWAITING_BLOCK_STATE = 3;
|
|
|
|
private static final int HAVE_BLOCK_STATE = 4;
|
|
|
|
private int feederState = IDLE_STATE;
|
|
|
|
private int messageId = -1;
|
|
|
|
|
|
|
|
private long lastPingTimestamp = System.currentTimeMillis();
|
|
|
|
private List<byte[]> signatures = new ArrayList<byte[]>();
|
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
private static Map<Pair<String, Integer>, BigDecimal> legacyATFees;
|
|
|
|
private static Map<Integer, List<TransactionData>> legacyATTransactions;
|
|
|
|
|
2018-08-02 09:02:33 +00:00
|
|
|
private v1feeder(String address, int port) throws InterruptedException {
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
try {
|
|
|
|
// Create new socket for connection to peer
|
|
|
|
this.socket = new Socket();
|
|
|
|
|
|
|
|
// Collate this.address and destination port
|
|
|
|
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
|
|
|
|
|
|
|
|
// Attempt to connect, with timeout from settings
|
|
|
|
this.socket.connect(socketAddress, CONNECTION_TIMEOUT);
|
|
|
|
break;
|
|
|
|
} catch (SocketTimeoutException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Timed out trying to connect to " + address + " - retrying");
|
2018-08-02 09:02:33 +00:00
|
|
|
Thread.sleep(1000);
|
|
|
|
this.socket = null;
|
|
|
|
} catch (Exception e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Failed to connect to " + address, e);
|
2018-08-02 09:02:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No connection after retries?
|
|
|
|
if (this.socket == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Enable TCP keep-alive packets
|
|
|
|
this.socket.setKeepAlive(true);
|
|
|
|
|
|
|
|
// Inactivity timeout
|
|
|
|
this.socket.setSoTimeout(INACTIVITY_TIMEOUT);
|
|
|
|
|
|
|
|
// Grab reference to output stream
|
|
|
|
this.out = socket.getOutputStream();
|
|
|
|
|
|
|
|
// Start main communication thread
|
|
|
|
this.start();
|
|
|
|
} catch (SocketException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Failed to set socket timeout for address " + address, e);
|
2018-08-02 09:02:33 +00:00
|
|
|
} catch (IOException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Failed to get output stream for address " + address, e);
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte[] createMessage(int type, boolean hasId, Integer id, byte[] data) throws IOException {
|
|
|
|
if (data == null)
|
|
|
|
data = new byte[0];
|
|
|
|
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
bytes.write(MAINNET_MAGIC);
|
|
|
|
|
|
|
|
bytes.write(Ints.toByteArray(type));
|
|
|
|
|
|
|
|
byte[] hasIdBytes = new byte[] { (byte) (hasId ? 1 : 0) };
|
|
|
|
bytes.write(hasIdBytes);
|
|
|
|
|
|
|
|
if (hasId) {
|
|
|
|
if (id == null)
|
|
|
|
id = (int) ((Math.random() * 1000000) + 1);
|
|
|
|
|
|
|
|
bytes.write(Ints.toByteArray(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes.write(Ints.toByteArray(data.length));
|
|
|
|
|
|
|
|
if (data.length > 0) {
|
|
|
|
byte[] checksum = Crypto.digest(data);
|
|
|
|
bytes.write(checksum, 0, CHECKSUM_LENGTH);
|
|
|
|
|
|
|
|
bytes.write(data);
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Creating message type [" + type + "] with " + (hasId ? "id [" + id + "]" : "no id") + " and data length " + data.length);
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
return bytes.toByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendMessage(byte[] message) throws IOException {
|
|
|
|
synchronized (this.out) {
|
|
|
|
this.out.write(message);
|
|
|
|
this.out.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processMessage(int type, int id, byte[] data) throws IOException {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Received message type [" + type + "] with id [" + id + "] and data length " + data.length);
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.wrap(data);
|
|
|
|
switch (type) {
|
|
|
|
case HEIGHT_TYPE:
|
|
|
|
int height = byteBuffer.getInt();
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Peer height: " + height);
|
2018-08-02 09:02:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGNATURES_TYPE:
|
|
|
|
// shove into list
|
|
|
|
int numSignatures = byteBuffer.getInt();
|
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
if (numSignatures == 0)
|
|
|
|
throw new RuntimeException("No signatures from peer - are we up to date?");
|
|
|
|
|
2018-08-02 09:02:33 +00:00
|
|
|
while (numSignatures-- > 0) {
|
|
|
|
byte[] signature = new byte[SIGNATURE_LENGTH];
|
|
|
|
byteBuffer.get(signature);
|
|
|
|
signatures.add(signature);
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("We now have " + signatures.size() + " signature(s) to process");
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
feederState = HAVE_HEADERS_STATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_TYPE:
|
|
|
|
// If messageId doesn't match then discard
|
|
|
|
if (id != this.messageId)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// read block and process
|
|
|
|
int claimedHeight = byteBuffer.getInt();
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Received block allegedly at height " + claimedHeight);
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
byte[] blockBytes = new byte[byteBuffer.remaining()];
|
|
|
|
byteBuffer.get(blockBytes);
|
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
Triple<BlockData, List<TransactionData>, List<ATStateData>> blockInfo = null;
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
blockInfo = BlockTransformer.fromBytes(blockBytes);
|
|
|
|
} catch (TransformationException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Couldn't parse block bytes from peer", e);
|
|
|
|
throw new RuntimeException("Couldn't parse block bytes from peer", e);
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
BlockData blockData = blockInfo.getA();
|
|
|
|
|
|
|
|
// Adjust AT state data to include fees
|
|
|
|
List<ATStateData> atStates = new ArrayList<ATStateData>();
|
|
|
|
for (ATStateData atState : blockInfo.getC()) {
|
|
|
|
BigDecimal fees = legacyATFees.get(new Pair<String, Integer>(atState.getATAddress(), claimedHeight));
|
|
|
|
ATData atData = repository.getATRepository().fromATAddress(atState.getATAddress());
|
|
|
|
|
|
|
|
atStates.add(new ATStateData(atState.getATAddress(), claimedHeight, atData.getCreation(), null, atState.getStateHash(), fees));
|
|
|
|
}
|
|
|
|
|
|
|
|
// AT-Transaction injection goes here!
|
|
|
|
List<TransactionData> transactions = blockInfo.getB();
|
|
|
|
List<TransactionData> atTransactions = legacyATTransactions.get(claimedHeight);
|
|
|
|
if (atTransactions != null) {
|
|
|
|
transactions.addAll(0, atTransactions);
|
|
|
|
blockData.setTransactionCount(blockData.getTransactionCount() + atTransactions.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = new Block(repository, blockData, transactions, atStates);
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
if (!block.isSignatureValid()) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Invalid block signature");
|
|
|
|
throw new RuntimeException("Invalid block signature");
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ValidationResult result = block.isValid();
|
|
|
|
|
|
|
|
if (result != ValidationResult.OK) {
|
2018-10-15 14:12:41 +00:00
|
|
|
LOGGER.error("Invalid block, validation result: " + result.name());
|
|
|
|
throw new RuntimeException("Invalid block, validation result: " + result.name());
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
block.process();
|
|
|
|
repository.saveChanges();
|
|
|
|
} catch (DataException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Unable to process block", e);
|
|
|
|
throw new RuntimeException("Unable to process block", e);
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
feederState = HAVE_BLOCK_STATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PING_TYPE:
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Sending pong for ping [" + id + "]");
|
2018-08-02 09:02:33 +00:00
|
|
|
byte[] pongMessage = createMessage(PING_TYPE, true, id, null);
|
|
|
|
sendMessage(pongMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERSION_TYPE:
|
2018-08-08 16:02:41 +00:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
long timestamp = byteBuffer.getLong();
|
2018-08-02 09:02:33 +00:00
|
|
|
int versionLength = byteBuffer.getInt();
|
|
|
|
byte[] versionBytes = new byte[versionLength];
|
|
|
|
byteBuffer.get(versionBytes);
|
|
|
|
String version = new String(versionBytes, Charset.forName("UTF-8"));
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Peer version info: " + version);
|
2018-08-02 09:02:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Discarding message type [" + type + "] with id [" + id + "] and data length " + data.length);
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int parseBuffer(byte[] buffer, int bufferEnd) throws IOException {
|
|
|
|
int newBufferEnd = bufferEnd;
|
|
|
|
|
|
|
|
try {
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer, 0, bufferEnd);
|
|
|
|
|
|
|
|
// Check magic
|
|
|
|
byte[] magic = new byte[MAGIC_LENGTH];
|
|
|
|
byteBuffer.get(magic);
|
|
|
|
if (!Arrays.equals(magic, MAINNET_MAGIC)) {
|
|
|
|
// bad data - discard whole buffer
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int type = byteBuffer.getInt();
|
|
|
|
|
|
|
|
byte[] hasId = new byte[HAS_ID_LENGTH];
|
|
|
|
byteBuffer.get(hasId);
|
|
|
|
|
|
|
|
int id = -1;
|
|
|
|
if (hasId[0] == (byte) 1)
|
|
|
|
id = byteBuffer.getInt();
|
|
|
|
|
|
|
|
int dataSize = byteBuffer.getInt();
|
|
|
|
byte[] data = new byte[dataSize];
|
|
|
|
if (dataSize > 0) {
|
|
|
|
byte[] checksum = new byte[CHECKSUM_LENGTH];
|
|
|
|
byteBuffer.get(checksum);
|
|
|
|
|
|
|
|
byteBuffer.get(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a full message - remove from buffer
|
|
|
|
int nextMessageOffset = byteBuffer.position();
|
|
|
|
newBufferEnd = bufferEnd - nextMessageOffset;
|
|
|
|
byteBuffer = null;
|
|
|
|
|
|
|
|
System.arraycopy(buffer, nextMessageOffset, buffer, 0, newBufferEnd);
|
|
|
|
|
|
|
|
// Process message
|
|
|
|
processMessage(type, id, data);
|
|
|
|
} catch (BufferUnderflowException e) {
|
|
|
|
// Not enough data
|
|
|
|
}
|
|
|
|
|
|
|
|
return newBufferEnd;
|
|
|
|
}
|
|
|
|
|
HSQLDB issue, resource leak prevention, v1 differences
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.
2018-08-07 14:44:41 +00:00
|
|
|
@Override
|
2018-08-02 09:02:33 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
DataInputStream in = new DataInputStream(socket.getInputStream());
|
|
|
|
byte[] buffer = new byte[2 * 1024 * 1024]; // 2MB
|
|
|
|
int bufferEnd = 0;
|
|
|
|
|
|
|
|
// Send our height
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
int height = repository.getBlockRepository().getBlockchainHeight();
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Sending our height " + height + " to peer");
|
2018-08-02 09:02:33 +00:00
|
|
|
byte[] heightMessage = createMessage(HEIGHT_TYPE, false, null, Ints.toByteArray(height));
|
|
|
|
sendMessage(heightMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Anything to read?
|
|
|
|
if (in.available() > 0) {
|
|
|
|
// read message
|
|
|
|
int numRead = in.read(buffer, bufferEnd, in.available());
|
|
|
|
if (numRead == -1) {
|
|
|
|
// input EOF
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Socket EOF");
|
2018-08-02 09:02:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufferEnd += numRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bufferEnd > 0) {
|
|
|
|
// attempt to parse
|
|
|
|
bufferEnd = parseBuffer(buffer, bufferEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we need to send a ping message?
|
|
|
|
if (System.currentTimeMillis() - lastPingTimestamp >= PING_INTERVAL) {
|
|
|
|
byte[] pingMessage = createMessage(PING_TYPE, true, null, null);
|
|
|
|
sendMessage(pingMessage);
|
|
|
|
lastPingTimestamp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] signature = null;
|
|
|
|
switch (feederState) {
|
|
|
|
case IDLE_STATE:
|
|
|
|
// Get signature from our highest block
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
BlockData blockData = repository.getBlockRepository().getLastBlock();
|
|
|
|
|
|
|
|
if (blockData != null)
|
|
|
|
signature = blockData.getSignature();
|
|
|
|
}
|
|
|
|
|
|
|
|
// done?
|
|
|
|
if (signature == null) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.warn("No last block in repository?");
|
2018-08-02 09:02:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Requesting more signatures...");
|
2018-08-02 09:02:33 +00:00
|
|
|
byte[] getSignaturesMessage = createMessage(GET_SIGNATURES_TYPE, true, null, signature);
|
|
|
|
sendMessage(getSignaturesMessage);
|
|
|
|
feederState = AWAITING_HEADERS_STATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HAVE_HEADERS_STATE:
|
|
|
|
case HAVE_BLOCK_STATE:
|
|
|
|
// request next block?
|
|
|
|
if (signatures.size() == 0) {
|
|
|
|
feederState = IDLE_STATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.trace("Requesting next block...");
|
2018-08-02 09:02:33 +00:00
|
|
|
signature = signatures.remove(0);
|
|
|
|
this.messageId = (int) ((Math.random() * 1000000) + 1);
|
|
|
|
byte[] getBlockMessage = createMessage(GET_BLOCK_TYPE, true, this.messageId, signature);
|
|
|
|
sendMessage(getBlockMessage);
|
|
|
|
feederState = AWAITING_BLOCK_STATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-08 16:02:41 +00:00
|
|
|
} catch (IOException | DataException | RuntimeException e) {
|
2018-08-02 09:02:33 +00:00
|
|
|
// give up
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Exiting", e);
|
2018-08-02 09:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.socket.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
private static void readLegacyATs(String legacyATPathname) {
|
|
|
|
legacyATFees = new HashMap<Pair<String, Integer>, BigDecimal>();
|
|
|
|
legacyATTransactions = new HashMap<Integer, List<TransactionData>>();
|
|
|
|
|
|
|
|
Path path = Paths.get(legacyATPathname);
|
|
|
|
|
|
|
|
JSONArray json = null;
|
|
|
|
|
|
|
|
try (BufferedReader in = Files.newBufferedReader(path)) {
|
|
|
|
json = (JSONArray) JSONValue.parseWithException(in);
|
|
|
|
} catch (IOException | ParseException e) {
|
|
|
|
throw new RuntimeException("Couldn't read legacy AT JSON file");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Object o : json) {
|
|
|
|
JSONObject entry = (JSONObject) o;
|
|
|
|
|
|
|
|
int height = Integer.parseInt((String) entry.get("height"));
|
|
|
|
long timestamp = (Long) entry.get("timestamp");
|
|
|
|
|
|
|
|
JSONArray transactionEntries = (JSONArray) entry.get("transactions");
|
|
|
|
|
|
|
|
List<TransactionData> transactions = new ArrayList<TransactionData>();
|
|
|
|
|
|
|
|
for (Object t : transactionEntries) {
|
|
|
|
JSONObject transactionEntry = (JSONObject) t;
|
|
|
|
|
|
|
|
String recipient = (String) transactionEntry.get("recipient");
|
|
|
|
String sender = (String) transactionEntry.get("sender");
|
|
|
|
BigDecimal amount = new BigDecimal((String) transactionEntry.get("amount")).setScale(8);
|
|
|
|
|
|
|
|
if (recipient.equals("1111111111111111111111111")) {
|
|
|
|
// fee
|
|
|
|
legacyATFees.put(new Pair<String, Integer>(sender, height), amount);
|
|
|
|
} else {
|
|
|
|
// Actual AT Transaction
|
|
|
|
String messageString = (String) transactionEntry.get("message");
|
|
|
|
byte[] message = messageString.isEmpty() ? new byte[0] : HashCode.fromString(messageString).asBytes();
|
|
|
|
int sequence = ((Long) transactionEntry.get("seq")).intValue();
|
|
|
|
byte[] reference = Base58.decode((String) transactionEntry.get("reference"));
|
|
|
|
|
|
|
|
// reference is AT's deploy tx signature
|
|
|
|
// sender's public key is genesis account
|
|
|
|
// zero fee
|
|
|
|
// timestamp is block's timestamp
|
|
|
|
// signature = duplicated hash of transaction data
|
|
|
|
|
|
|
|
BigDecimal fee = BigDecimal.ZERO.setScale(8);
|
|
|
|
|
|
|
|
TransactionData transactionData = new ATTransactionData(sender, recipient, amount, Asset.QORA, message, fee, timestamp, reference);
|
|
|
|
byte[] digest;
|
|
|
|
try {
|
|
|
|
digest = Crypto.digest(ATTransactionTransformer.toBytes(transactionData));
|
|
|
|
byte[] signature = Bytes.concat(digest, digest);
|
|
|
|
|
|
|
|
transactionData = new ATTransactionData(sender, recipient, amount, Asset.QORA, message, fee, timestamp, reference, signature);
|
|
|
|
} catch (TransformationException e) {
|
|
|
|
throw new RuntimeException("Couldn't transform AT Transaction into bytes", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sequence > transactions.size())
|
|
|
|
transactions.add(transactionData);
|
|
|
|
else
|
|
|
|
transactions.add(sequence, transactionData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!transactions.isEmpty())
|
|
|
|
legacyATTransactions.put(height, transactions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 09:02:33 +00:00
|
|
|
public static void main(String[] args) {
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
if (args.length < 2 || args.length > 3) {
|
|
|
|
System.err.println("usage: v1feeder legacy-AT-json v1-node-address [port]");
|
|
|
|
System.err.println("example: v1feeder legacy-ATs.json 10.0.0.100 9084");
|
2018-08-02 09:02:33 +00:00
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
String legacyATPathname = args[0];
|
|
|
|
readLegacyATs(legacyATPathname);
|
|
|
|
|
2018-08-02 09:02:33 +00:00
|
|
|
try {
|
2018-12-12 12:13:06 +00:00
|
|
|
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(Controller.connectionUrl);
|
2018-12-04 16:34:55 +00:00
|
|
|
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
2018-08-02 09:02:33 +00:00
|
|
|
} catch (DataException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Couldn't connect to repository", e);
|
2018-08-02 09:02:33 +00:00
|
|
|
System.exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
BlockChain.validate();
|
|
|
|
} catch (DataException e) {
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.error("Couldn't validate repository", e);
|
2018-08-02 09:02:33 +00:00
|
|
|
System.exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// connect to v1 node
|
Finally syncs with qora1 chain!
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!
2018-10-26 16:47:47 +00:00
|
|
|
String address = args[1];
|
|
|
|
int port = args.length > 2 ? Integer.valueOf(args[2]) : DEFAULT_PORT;
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
new v1feeder(address, port).join();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:02:41 +00:00
|
|
|
LOGGER.info("Exiting v1feeder");
|
2018-08-02 09:02:33 +00:00
|
|
|
|
|
|
|
try {
|
2018-12-04 16:34:55 +00:00
|
|
|
RepositoryManager.closeRepositoryFactory();
|
2018-08-02 09:02:33 +00:00
|
|
|
} catch (DataException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|