mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-30 09:05:52 +00:00
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!
50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package qora.assets;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
|
|
import database.DB;
|
|
import qora.account.PublicKeyAccount;
|
|
|
|
public class Asset {
|
|
|
|
public static final long QORA = 0L;
|
|
|
|
// Properties
|
|
private Long key;
|
|
private PublicKeyAccount owner;
|
|
private String name;
|
|
private String description;
|
|
private long quantity;
|
|
private boolean isDivisible;
|
|
private byte[] reference;
|
|
|
|
public Asset(Long key, PublicKeyAccount owner, String name, String description, long quantity, boolean isDivisible, byte[] reference) {
|
|
this.key = key;
|
|
this.owner = owner;
|
|
this.name = name;
|
|
this.description = description;
|
|
this.quantity = quantity;
|
|
this.isDivisible = isDivisible;
|
|
this.reference = reference;
|
|
}
|
|
|
|
public Asset(PublicKeyAccount owner, String name, String description, long quantity, boolean isDivisible, byte[] reference) {
|
|
this(null, owner, name, description, quantity, isDivisible, reference);
|
|
}
|
|
|
|
// Load/Save
|
|
|
|
public void save(Connection connection) throws SQLException {
|
|
String sql = DB.formatInsertWithPlaceholders("Assets", "asset", "owner", "asset_name", "description", "quantity", "is_divisible", "reference");
|
|
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
|
DB.bindInsertPlaceholders(preparedStatement, this.key, this.owner.getAddress(), this.name, this.description, this.quantity, this.isDivisible,
|
|
this.reference);
|
|
preparedStatement.execute();
|
|
|
|
if (this.key == null)
|
|
this.key = DB.callIdentity(connection);
|
|
}
|
|
}
|