mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-11 17:55:50 +00:00
First stub files for conversion to data access layer, etc.
This commit is contained in:
parent
5b78268915
commit
2ea6f12b3c
47
src/data/account/Account.java
Normal file
47
src/data/account/Account.java
Normal file
@ -0,0 +1,47 @@
|
||||
package data.account;
|
||||
|
||||
public class Account {
|
||||
|
||||
// Properties
|
||||
protected String address;
|
||||
protected byte[] reference;
|
||||
|
||||
// Constructors
|
||||
|
||||
protected Account() {
|
||||
}
|
||||
|
||||
public Account(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
// Getters/Setters
|
||||
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
public byte[] getReference() {
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public void setReference(byte[] reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
// Comparison
|
||||
|
||||
@Override
|
||||
public boolean equals(Object b) {
|
||||
if (!(b instanceof Account))
|
||||
return false;
|
||||
|
||||
return this.getAddress().equals(((Account) b).getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getAddress().hashCode();
|
||||
}
|
||||
|
||||
}
|
9
src/data/account/GenesisAccount.java
Normal file
9
src/data/account/GenesisAccount.java
Normal file
@ -0,0 +1,9 @@
|
||||
package data.account;
|
||||
|
||||
public final class GenesisAccount extends PublicKeyAccount {
|
||||
|
||||
public GenesisAccount() {
|
||||
super(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1 });
|
||||
}
|
||||
|
||||
}
|
27
src/data/account/PublicKeyAccount.java
Normal file
27
src/data/account/PublicKeyAccount.java
Normal file
@ -0,0 +1,27 @@
|
||||
package data.account;
|
||||
|
||||
import qora.crypto.Crypto;
|
||||
|
||||
public class PublicKeyAccount extends Account {
|
||||
|
||||
// Properties
|
||||
protected byte[] publicKey;
|
||||
|
||||
// Constructors
|
||||
|
||||
public PublicKeyAccount(byte[] publicKey) {
|
||||
super(Crypto.toAddress(publicKey));
|
||||
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
protected PublicKeyAccount() {
|
||||
}
|
||||
|
||||
// Getters/Setters
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return this.publicKey;
|
||||
}
|
||||
|
||||
}
|
37
src/data/transaction/GenesisTransaction.java
Normal file
37
src/data/transaction/GenesisTransaction.java
Normal file
@ -0,0 +1,37 @@
|
||||
package data.transaction;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import data.account.Account;
|
||||
import data.account.GenesisAccount;
|
||||
|
||||
public class GenesisTransaction extends Transaction {
|
||||
|
||||
// Properties
|
||||
private Account recipient;
|
||||
private BigDecimal amount;
|
||||
|
||||
// Constructors
|
||||
|
||||
public GenesisTransaction(String recipient, BigDecimal amount, long timestamp, byte[] signature) {
|
||||
super(TransactionType.GENESIS, BigDecimal.ZERO, new GenesisAccount(), timestamp, signature);
|
||||
|
||||
this.recipient = new Account(recipient);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public GenesisTransaction(String recipient, BigDecimal amount, long timestamp) {
|
||||
this(recipient, amount, timestamp, null);
|
||||
}
|
||||
|
||||
// Getters/Setters
|
||||
|
||||
public Account getRecipient() {
|
||||
return this.recipient;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
}
|
79
src/data/transaction/Transaction.java
Normal file
79
src/data/transaction/Transaction.java
Normal file
@ -0,0 +1,79 @@
|
||||
package data.transaction;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
import data.account.PublicKeyAccount;
|
||||
|
||||
public abstract class Transaction {
|
||||
|
||||
// Transaction types
|
||||
public enum TransactionType {
|
||||
GENESIS(1), PAYMENT(2), REGISTER_NAME(3), UPDATE_NAME(4), SELL_NAME(5), CANCEL_SELL_NAME(6), BUY_NAME(7), CREATE_POLL(8), VOTE_ON_POLL(9), ARBITRARY(
|
||||
10), ISSUE_ASSET(11), TRANSFER_ASSET(12), CREATE_ASSET_ORDER(13), CANCEL_ASSET_ORDER(14), MULTIPAYMENT(15), DEPLOY_AT(16), MESSAGE(17);
|
||||
|
||||
public final int value;
|
||||
|
||||
private final static Map<Integer, TransactionType> map = stream(TransactionType.values()).collect(toMap(type -> type.value, type -> type));
|
||||
|
||||
TransactionType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static TransactionType valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Properties shared with all transaction types
|
||||
protected TransactionType type;
|
||||
protected PublicKeyAccount creator;
|
||||
protected long timestamp;
|
||||
protected byte[] reference;
|
||||
protected BigDecimal fee;
|
||||
protected byte[] signature;
|
||||
|
||||
// Constructors
|
||||
|
||||
public Transaction(TransactionType type, BigDecimal fee, PublicKeyAccount creator, long timestamp, byte[] reference, byte[] signature) {
|
||||
this.fee = fee;
|
||||
this.type = type;
|
||||
this.creator = creator;
|
||||
this.timestamp = timestamp;
|
||||
this.reference = reference;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public Transaction(TransactionType type, BigDecimal fee, PublicKeyAccount creator, long timestamp, byte[] reference) {
|
||||
this(type, fee, creator, timestamp, reference, null);
|
||||
}
|
||||
|
||||
// Getters/setters
|
||||
|
||||
public TransactionType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public PublicKeyAccount getCreator() {
|
||||
return this.creator;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public byte[] getReference() {
|
||||
return this.reference;
|
||||
}
|
||||
|
||||
public BigDecimal getFee() {
|
||||
return this.fee;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user