Java Code Examples for com.google.common.primitives.Bytes#ensureCapacity()
The following examples show how to use
com.google.common.primitives.Bytes#ensureCapacity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignaturesMessage.java From Qora with MIT License | 6 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE LENGTH int length = this.signatures.size(); byte[] lengthBytes = Ints.toByteArray(length); lengthBytes = Bytes.ensureCapacity(lengthBytes, DATA_LENGTH, 0); data = Bytes.concat(data, lengthBytes); //WRITE SIGNATURES for(byte[] header: this.signatures) { //WRITE SIGNATURE data = Bytes.concat(data, header); } //ADD CHECKSUM data = Bytes.concat(super.toBytes(), this.generateChecksum(data), data); return data; }
Example 2
Source File: GenesisTransaction.java From Qora with MIT License | 6 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(GENESIS_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE RECIPIENT data = Bytes.concat(data, Base58.decode(this.recipient.getAddress())); //WRITE AMOUNT byte[] amountBytes = this.amount.unscaledValue().toByteArray(); byte[] fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); return data; }
Example 3
Source File: SellNameTransaction.java From Qora with MIT License | 5 votes |
@Override public boolean isSignatureValid() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(SELL_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE OWNER data = Bytes.concat(data, this.owner.getPublicKey()); //WRITE NAMESALE data = Bytes.concat(data, this.nameSale.toBytes()); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().verify(this.owner.getPublicKey(), this.signature, data); }
Example 4
Source File: SellNameTransaction.java From Qora with MIT License | 5 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(SELL_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE OWNER data = Bytes.concat(data, this.owner.getPublicKey()); //WRITE NAMESALE data = Bytes.concat(data, this.nameSale.toBytes()); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 5
Source File: CreatePollTransaction.java From Qora with MIT License | 5 votes |
public static byte[] generateSignature(DBSet db, PrivateKeyAccount creator, Poll poll, BigDecimal fee, long timestamp) { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(REGISTER_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, creator.getLastReference(db)); //WRITE CREATOR data = Bytes.concat(data, creator.getPublicKey()); //WRITE POLL data = Bytes.concat(data , poll.toBytes()); //WRITE FEE byte[] feeBytes = fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().sign(creator, data); }
Example 6
Source File: IssueAssetTransaction.java From Qora with MIT License | 5 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(ISSUE_ASSET_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE ISSUER data = Bytes.concat(data, this.issuer.getPublicKey()); //WRITE ASSET data = Bytes.concat(data , this.asset.toBytes(true)); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 7
Source File: RegisterNameTransaction.java From Qora with MIT License | 5 votes |
public boolean isSignatureValid() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(REGISTER_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE REGISTRANT data = Bytes.concat(data, this.registrant.getPublicKey()); //WRITE NAME data = Bytes.concat(data , this.name.toBytes()); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().verify(this.registrant.getPublicKey(), this.signature, data); }
Example 8
Source File: RegisterNameTransaction.java From Qora with MIT License | 5 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(REGISTER_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE REGISTRANT data = Bytes.concat(data, this.registrant.getPublicKey()); //WRITE NAME data = Bytes.concat(data , this.name.toBytes()); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 9
Source File: MultiPaymentTransaction.java From Qora with MIT License | 5 votes |
public static byte[] generateSignature(DBSet db, PrivateKeyAccount sender, List<Payment> payments, BigDecimal fee, long timestamp) { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(MULTI_PAYMENT_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, sender.getLastReference(db)); //WRITE SENDER data = Bytes.concat(data , sender.getPublicKey()); //WRITE PAYMENTS SIZE int paymentsLength = payments.size(); byte[] paymentsLengthBytes = Ints.toByteArray(paymentsLength); data = Bytes.concat(data, paymentsLengthBytes); //WRITE PAYMENTS for(Payment payment: payments) { data = Bytes.concat(payment.toBytes()); } //WRITE FEE byte[] feeBytes = fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGN return Crypto.getInstance().sign(sender, data); }
Example 10
Source File: MultiPaymentTransaction.java From Qora with MIT License | 5 votes |
public boolean isSignatureValid() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(MULTI_PAYMENT_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE SENDER data = Bytes.concat(data , this.sender.getPublicKey()); //WRITE PAYMENTS SIZE int paymentsLength = this.payments.size(); byte[] paymentsLengthBytes = Ints.toByteArray(paymentsLength); data = Bytes.concat(data, paymentsLengthBytes); //WRITE PAYMENTS for(Payment payment: this.payments) { data = Bytes.concat(payment.toBytes()); } //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().verify(this.sender.getPublicKey(), this.signature, data); }
Example 11
Source File: BuyNameTransaction.java From Qora with MIT License | 5 votes |
@Override public boolean isSignatureValid() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(BUY_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE BUYER data = Bytes.concat(data, this.buyer.getPublicKey()); //WRITE NAME SALE data = Bytes.concat(data, this.nameSale.toBytes()); //WRITE SELLER data = Bytes.concat(data, Base58.decode(this.seller.getAddress())); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().verify(this.buyer.getPublicKey(), this.signature, data); }
Example 12
Source File: UpdateNameTransaction.java From Qora with MIT License | 5 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(UPDATE_NAME_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE OWNER data = Bytes.concat(data, this.owner.getPublicKey()); //WRITE NAME data = Bytes.concat(data , this.name.toBytes()); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 13
Source File: GenesisTransaction.java From Qora with MIT License | 5 votes |
private static byte[] generateSignature(Account recipient, BigDecimal amount, long timestamp) { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(GENESIS_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE RECIPIENT data = Bytes.concat(data, Base58.decode(recipient.getAddress())); //WRITE AMOUNT byte[] amountBytes = amount.unscaledValue().toByteArray(); byte[] fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); //DIGEST byte[] digest = Crypto.getInstance().digest(data); digest = Bytes.concat(digest, digest); return digest; }
Example 14
Source File: VersionMessage.java From Qora with MIT License | 5 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE HEIGHT byte[] heightBytes = Ints.toByteArray(this.height); heightBytes = Bytes.ensureCapacity(heightBytes, HEIGHT_LENGTH, 0); data = Bytes.concat(data, heightBytes); //ADD CHECKSUM data = Bytes.concat(super.toBytes(), this.generateChecksum(data), data); return data; }
Example 15
Source File: MultiPaymentTransaction.java From Qora with MIT License | 4 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(MULTI_PAYMENT_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE SENDER data = Bytes.concat(data , this.sender.getPublicKey()); //WRITE PAYMENTS SIZE int paymentsLength = this.payments.size(); byte[] paymentsLengthBytes = Ints.toByteArray(paymentsLength); data = Bytes.concat(data, paymentsLengthBytes); //WRITE PAYMENTS for(Payment payment: this.payments) { data = Bytes.concat(data, payment.toBytes()); } //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); byte[] fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 16
Source File: CreateOrderTransaction.java From Qora with MIT License | 4 votes |
@Override public byte[] toBytes() { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(CREATE_ORDER_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, this.reference); //WRITE CREATOR data = Bytes.concat(data, this.creator.getPublicKey()); //WRITE HAVE byte[] haveBytes = Longs.toByteArray(this.order.getHave()); haveBytes = Bytes.ensureCapacity(haveBytes, HAVE_LENGTH, 0); data = Bytes.concat(data, haveBytes); //WRITE WANT byte[] wantBytes = Longs.toByteArray(this.order.getWant()); wantBytes = Bytes.ensureCapacity(wantBytes, WANT_LENGTH, 0); data = Bytes.concat(data, wantBytes); //WRITE AMOUNT byte[] amountBytes = this.order.getAmount().unscaledValue().toByteArray(); byte[] fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); //WRITE PRICE byte[] priceBytes = this.order.getPrice().unscaledValue().toByteArray(); fill = new byte[PRICE_LENGTH - priceBytes.length]; priceBytes = Bytes.concat(fill, priceBytes); data = Bytes.concat(data, priceBytes); //WRITE FEE byte[] feeBytes = this.fee.unscaledValue().toByteArray(); fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGNATURE data = Bytes.concat(data, this.signature); return data; }
Example 17
Source File: Block.java From Qora with MIT License | 4 votes |
public boolean isSignatureValid() { //VALIDATE BLOCK SIGNATURE byte[] data = new byte[0]; //WRITE PARENT GENERATOR SIGNATURE byte[] generatorSignature = Arrays.copyOfRange(this.reference, 0, GENERATOR_SIGNATURE_LENGTH); data = Bytes.concat(data, generatorSignature); //WRITE GENERATING BALANCE byte[] baseTargetBytes = Longs.toByteArray(this.generatingBalance); data = Bytes.concat(data, baseTargetBytes); //WRITE GENERATOR byte[] generatorBytes = Bytes.ensureCapacity(this.generator.getPublicKey(), GENERATOR_LENGTH, 0); data = Bytes.concat(data, generatorBytes); if(!Crypto.getInstance().verify(this.generator.getPublicKey(), this.generatorSignature, data)) { return false; } //VALIDATE TRANSACTIONS SIGNATURE data = this.generatorSignature; for(Transaction transaction: this.getTransactions()) { //CHECK IF TRANSACTION SIGNATURE IS VALID if(!transaction.isSignatureValid()) { return false; } //ADD SIGNATURE TO DATA data = Bytes.concat(data, transaction.getSignature()); } if(!Crypto.getInstance().verify(this.generator.getPublicKey(), this.transactionsSignature, data)) { return false; } return true; }
Example 18
Source File: CreateOrderTransaction.java From Qora with MIT License | 4 votes |
public static byte[] generateSignature(DBSet db, PrivateKeyAccount creator, long have, long want, BigDecimal amount, BigDecimal price, BigDecimal fee, long timestamp) { byte[] data = new byte[0]; Order order = new Order(null, creator, have, want, amount, price, timestamp); //WRITE TYPE byte[] typeBytes = Ints.toByteArray(CREATE_ORDER_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, creator.getLastReference(db)); //WRITE CREATOR data = Bytes.concat(data, creator.getPublicKey()); //WRITE HAVE byte[] haveBytes = Longs.toByteArray(order.getHave()); haveBytes = Bytes.ensureCapacity(haveBytes, HAVE_LENGTH, 0); data = Bytes.concat(data, haveBytes); //WRITE WANT byte[] wantBytes = Longs.toByteArray(order.getWant()); wantBytes = Bytes.ensureCapacity(wantBytes, WANT_LENGTH, 0); data = Bytes.concat(data, wantBytes); //WRITE AMOUNT byte[] amountBytes = order.getAmount().unscaledValue().toByteArray(); byte[] fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); //WRITE PRICE byte[] priceBytes = order.getPrice().unscaledValue().toByteArray(); fill = new byte[FEE_LENGTH - priceBytes.length]; priceBytes = Bytes.concat(fill, priceBytes); data = Bytes.concat(data, priceBytes); //WRITE FEE byte[] feeBytes = fee.unscaledValue().toByteArray(); fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); return Crypto.getInstance().sign(creator, data); }
Example 19
Source File: PaymentTransaction.java From Qora with MIT License | 4 votes |
public static byte[] generateSignature(DBSet db, PrivateKeyAccount sender, Account recipient, BigDecimal amount, BigDecimal fee, long timestamp) { byte[] data = new byte[0]; //WRITE TYPE byte[] typeBytes = Ints.toByteArray(PAYMENT_TRANSACTION); typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0); data = Bytes.concat(data, typeBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); //WRITE REFERENCE data = Bytes.concat(data, sender.getLastReference(db)); //WRITE SENDER data = Bytes.concat(data , sender.getPublicKey()); try { //WRITE RECIPIENT data = Bytes.concat(data, Base58.decode(recipient.getAddress())); } catch(Exception e) { //ERROR DECODING ADDRESS } //WRITE AMOUNT byte[] amountBytes = amount.unscaledValue().toByteArray(); byte[] fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); //WRITE FEE byte[] feeBytes = fee.unscaledValue().toByteArray(); fill = new byte[FEE_LENGTH - feeBytes.length]; feeBytes = Bytes.concat(fill, feeBytes); data = Bytes.concat(data, feeBytes); //SIGN return Crypto.getInstance().sign(sender, data); }
Example 20
Source File: Order.java From Qora with MIT License | 4 votes |
public byte[] toBytes() { byte[] data = new byte[0]; //WRITE ID byte[] idBytes = this.id.toByteArray(); byte[] fill = new byte[ID_LENGTH - idBytes.length]; idBytes = Bytes.concat(fill, idBytes); data = Bytes.concat(data, idBytes); //WRITE CREATOR try { data = Bytes.concat(data , Base58.decode(this.creator.getAddress())); } catch(Exception e) { //DECODE EXCEPTION } //WRITE HAVE byte[] haveBytes = Longs.toByteArray(this.have); haveBytes = Bytes.ensureCapacity(haveBytes, HAVE_LENGTH, 0); data = Bytes.concat(data, haveBytes); //WRITE WANT byte[] wantBytes = Longs.toByteArray(this.want); wantBytes = Bytes.ensureCapacity(wantBytes, WANT_LENGTH, 0); data = Bytes.concat(data, wantBytes); //WRITE AMOUNT byte[] amountBytes = this.amount.unscaledValue().toByteArray(); fill = new byte[AMOUNT_LENGTH - amountBytes.length]; amountBytes = Bytes.concat(fill, amountBytes); data = Bytes.concat(data, amountBytes); //WRITE FULFILLED byte[] fulfilledBytes = this.fulfilled.unscaledValue().toByteArray(); fill = new byte[FULFILLED_LENGTH - fulfilledBytes.length]; fulfilledBytes = Bytes.concat(fill, fulfilledBytes); data = Bytes.concat(data, fulfilledBytes); //WRITE PRICE byte[] priceBytes = this.price.unscaledValue().toByteArray(); fill = new byte[PRICE_LENGTH - priceBytes.length]; priceBytes = Bytes.concat(fill, priceBytes); data = Bytes.concat(data, priceBytes); //WRITE TIMESTAMP byte[] timestampBytes = Longs.toByteArray(this.timestamp); timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0); data = Bytes.concat(data, timestampBytes); return data; }