com.google.common.primitives.Bytes#ensureCapacity ( )源码实例Demo

下面列出了com.google.common.primitives.Bytes#ensureCapacity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Qora   文件: SignaturesMessage.java
@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;
}
 
源代码2 项目: Qora   文件: GenesisTransaction.java
@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;
}
 
源代码3 项目: Qora   文件: VersionMessage.java
@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;
}
 
源代码4 项目: Qora   文件: GenesisTransaction.java
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;
}
 
源代码5 项目: Qora   文件: UpdateNameTransaction.java
@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;
}
 
源代码6 项目: Qora   文件: BuyNameTransaction.java
@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);
}
 
源代码7 项目: Qora   文件: MultiPaymentTransaction.java
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);
}
 
源代码8 项目: Qora   文件: MultiPaymentTransaction.java
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);
}
 
源代码9 项目: Qora   文件: RegisterNameTransaction.java
@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;
}
 
源代码10 项目: Qora   文件: RegisterNameTransaction.java
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);
}
 
源代码11 项目: Qora   文件: IssueAssetTransaction.java
@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;
}
 
源代码12 项目: Qora   文件: CreatePollTransaction.java
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);
}
 
源代码13 项目: Qora   文件: SellNameTransaction.java
@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;	
}
 
源代码14 项目: Qora   文件: SellNameTransaction.java
@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);
}
 
源代码15 项目: Qora   文件: Order.java
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;
}
 
源代码16 项目: Qora   文件: CreateOrderTransaction.java
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);
}
 
源代码17 项目: Qora   文件: CreateOrderTransaction.java
@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;
}
 
源代码18 项目: Qora   文件: MultiPaymentTransaction.java
@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;
}
 
源代码19 项目: Qora   文件: Block.java
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;
}
 
源代码20 项目: Qora   文件: PaymentTransaction.java
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);
}