use of com.google.flatbuffers.FlatBufferBuilder in project nem2-sdk-java by nemtech.
the class ModifyMultisigAccountTransaction method generateBytes.
byte[] generateBytes() {
FlatBufferBuilder builder = new FlatBufferBuilder();
BigInteger deadlineBigInt = BigInteger.valueOf(getDeadline().getInstant());
int[] fee = new int[] { 0, 0 };
int version = (int) Long.parseLong(Integer.toHexString(getNetworkType().getValue()) + "0" + Integer.toHexString(getVersion()), 16);
// Create Modifications
int[] modificationsBuffers = new int[modifications.size()];
for (int i = 0; i < modifications.size(); ++i) {
MultisigCosignatoryModification multisigCosignatoryModification = modifications.get(i);
byte[] byteCosignatoryPublicKey = HexEncoder.getBytes(multisigCosignatoryModification.getCosignatoryPublicAccount().getPublicKey());
int cosignatoryPublicKey = CosignatoryModificationBuffer.createCosignatoryPublicKeyVector(builder, byteCosignatoryPublicKey);
CosignatoryModificationBuffer.startCosignatoryModificationBuffer(builder);
CosignatoryModificationBuffer.addType(builder, multisigCosignatoryModification.getType().getValue());
CosignatoryModificationBuffer.addCosignatoryPublicKey(builder, cosignatoryPublicKey);
modificationsBuffers[i] = CosignatoryModificationBuffer.endCosignatoryModificationBuffer(builder);
}
// Create Vectors
int signatureVector = MultisigAggregateModificationTransactionBuffer.createSignatureVector(builder, new byte[64]);
int signerVector = MultisigAggregateModificationTransactionBuffer.createSignerVector(builder, new byte[32]);
int deadlineVector = MultisigAggregateModificationTransactionBuffer.createDeadlineVector(builder, UInt64.fromBigInteger(deadlineBigInt));
int feeVector = MultisigAggregateModificationTransactionBuffer.createFeeVector(builder, fee);
int modificationsVector = TransferTransactionBuffer.createMosaicsVector(builder, modificationsBuffers);
// replace by the all numbers sum or add a comment explaining this
int fixSize = 123;
MultisigAggregateModificationTransactionBuffer.startMultisigAggregateModificationTransactionBuffer(builder);
MultisigAggregateModificationTransactionBuffer.addSize(builder, fixSize + (33 * modifications.size()));
MultisigAggregateModificationTransactionBuffer.addSignature(builder, signatureVector);
MultisigAggregateModificationTransactionBuffer.addSigner(builder, signerVector);
MultisigAggregateModificationTransactionBuffer.addVersion(builder, version);
MultisigAggregateModificationTransactionBuffer.addType(builder, getType().getValue());
MultisigAggregateModificationTransactionBuffer.addFee(builder, feeVector);
MultisigAggregateModificationTransactionBuffer.addDeadline(builder, deadlineVector);
MultisigAggregateModificationTransactionBuffer.addMinApprovalDelta(builder, minApprovalDelta);
MultisigAggregateModificationTransactionBuffer.addMinRemovalDelta(builder, minRemovalDelta);
MultisigAggregateModificationTransactionBuffer.addNumModifications(builder, modifications.size());
MultisigAggregateModificationTransactionBuffer.addModifications(builder, modificationsVector);
int codedTransaction = MultisigAggregateModificationTransactionBuffer.endMultisigAggregateModificationTransactionBuffer(builder);
builder.finish(codedTransaction);
return schema.serialize(builder.sizedByteArray());
}
use of com.google.flatbuffers.FlatBufferBuilder in project nem2-sdk-java by nemtech.
the class MosaicDefinitionTransaction method generateBytes.
byte[] generateBytes() {
FlatBufferBuilder builder = new FlatBufferBuilder();
BigInteger deadlineBigInt = BigInteger.valueOf(getDeadline().getInstant());
int[] fee = new int[] { 0, 0 };
int version = (int) Long.parseLong(Integer.toHexString(getNetworkType().getValue()) + "0" + Integer.toHexString(getVersion()), 16);
int flags = 0;
if (mosaicProperties.isSupplyMutable()) {
flags += 1;
}
if (mosaicProperties.isTransferable()) {
flags += 2;
}
if (mosaicProperties.isLevyMutable()) {
flags += 4;
}
// Create Vectors
int signatureVector = MosaicDefinitionCreationTransactionBuffer.createSignatureVector(builder, new byte[64]);
int signerVector = MosaicDefinitionCreationTransactionBuffer.createSignerVector(builder, new byte[32]);
int deadlineVector = MosaicDefinitionCreationTransactionBuffer.createDeadlineVector(builder, UInt64.fromBigInteger(deadlineBigInt));
int feeVector = MosaicDefinitionCreationTransactionBuffer.createFeeVector(builder, fee);
int mosaicIdVector = MosaicDefinitionCreationTransactionBuffer.createParentIdVector(builder, UInt64.fromBigInteger(mosaicId.getId()));
int namespaceIdVector = MosaicDefinitionCreationTransactionBuffer.createParentIdVector(builder, UInt64.fromBigInteger(namespaceId.getId()));
int durationVector = MosaicDefinitionCreationTransactionBuffer.createDurationVector(builder, UInt64.fromBigInteger(mosaicProperties.getDuration()));
// replace by the all numbers sum or add a comment explaining this
int fixSize = 149;
int name = builder.createString(mosaicName);
MosaicDefinitionCreationTransactionBuffer.startMosaicDefinitionCreationTransactionBuffer(builder);
MosaicDefinitionCreationTransactionBuffer.addSize(builder, fixSize + mosaicName.length());
MosaicDefinitionCreationTransactionBuffer.addSignature(builder, signatureVector);
MosaicDefinitionCreationTransactionBuffer.addSigner(builder, signerVector);
MosaicDefinitionCreationTransactionBuffer.addVersion(builder, version);
MosaicDefinitionCreationTransactionBuffer.addType(builder, getType().getValue());
MosaicDefinitionCreationTransactionBuffer.addFee(builder, feeVector);
MosaicDefinitionCreationTransactionBuffer.addDeadline(builder, deadlineVector);
MosaicDefinitionCreationTransactionBuffer.addMosaicId(builder, mosaicIdVector);
MosaicDefinitionCreationTransactionBuffer.addParentId(builder, namespaceIdVector);
MosaicDefinitionCreationTransactionBuffer.addMosaicNameLength(builder, mosaicName.length());
MosaicDefinitionCreationTransactionBuffer.addNumOptionalProperties(builder, 1);
MosaicDefinitionCreationTransactionBuffer.addFlags(builder, flags);
MosaicDefinitionCreationTransactionBuffer.addDivisibility(builder, mosaicProperties.getDivisibility());
MosaicDefinitionCreationTransactionBuffer.addMosaicName(builder, name);
MosaicDefinitionCreationTransactionBuffer.addIndicateDuration(builder, 2);
MosaicDefinitionCreationTransactionBuffer.addDuration(builder, durationVector);
int codedTransaction = MosaicDefinitionCreationTransactionBuffer.endMosaicDefinitionCreationTransactionBuffer(builder);
builder.finish(codedTransaction);
return schema.serialize(builder.sizedByteArray());
}
use of com.google.flatbuffers.FlatBufferBuilder in project nem2-sdk-java by nemtech.
the class SecretProofTransaction method generateBytes.
@Override
byte[] generateBytes() {
FlatBufferBuilder builder = new FlatBufferBuilder();
BigInteger deadlineBigInt = BigInteger.valueOf(getDeadline().getInstant());
int[] fee = new int[] { 0, 0 };
int version = (int) Long.parseLong(Integer.toHexString(getNetworkType().getValue()) + "0" + Integer.toHexString(getVersion()), 16);
// Create Vectors
int signatureVector = SecretProofTransactionBuffer.createSignatureVector(builder, new byte[64]);
int signerVector = SecretProofTransactionBuffer.createSignerVector(builder, new byte[32]);
int deadlineVector = SecretProofTransactionBuffer.createDeadlineVector(builder, UInt64.fromBigInteger(deadlineBigInt));
int feeVector = SecretProofTransactionBuffer.createFeeVector(builder, fee);
int secretVector = SecretProofTransactionBuffer.createSecretVector(builder, Hex.decode(secret));
int proofVector = SecretProofTransactionBuffer.createProofVector(builder, Hex.decode(proof));
SecretProofTransactionBuffer.startSecretProofTransactionBuffer(builder);
SecretProofTransactionBuffer.addSize(builder, 187 + Hex.decode(proof).length);
SecretProofTransactionBuffer.addSignature(builder, signatureVector);
SecretProofTransactionBuffer.addSigner(builder, signerVector);
SecretProofTransactionBuffer.addVersion(builder, version);
SecretProofTransactionBuffer.addType(builder, getType().getValue());
SecretProofTransactionBuffer.addFee(builder, feeVector);
SecretProofTransactionBuffer.addDeadline(builder, deadlineVector);
SecretProofTransactionBuffer.addHashAlgorithm(builder, hashType.getValue());
SecretProofTransactionBuffer.addSecret(builder, secretVector);
SecretProofTransactionBuffer.addProofSize(builder, Hex.decode(proof).length);
SecretProofTransactionBuffer.addProof(builder, proofVector);
int codedSecretProof = SecretProofTransactionBuffer.endSecretProofTransactionBuffer(builder);
builder.finish(codedSecretProof);
return schema.serialize(builder.sizedByteArray());
}
use of com.google.flatbuffers.FlatBufferBuilder in project nem2-sdk-java by nemtech.
the class TransferTransaction method generateBytes.
byte[] generateBytes() {
FlatBufferBuilder builder = new FlatBufferBuilder();
BigInteger deadlineBigInt = BigInteger.valueOf(getDeadline().getInstant());
int[] fee = new int[] { 0, 0 };
int version = (int) Long.parseLong(Integer.toHexString(getNetworkType().getValue()) + "0" + Integer.toHexString(getVersion()), 16);
// Create Message
byte[] bytePayload = message.getPayload().getBytes(StandardCharsets.UTF_8);
int payload = MessageBuffer.createPayloadVector(builder, bytePayload);
MessageBuffer.startMessageBuffer(builder);
MessageBuffer.addType(builder, message.getType());
MessageBuffer.addPayload(builder, payload);
int message = MessageBuffer.endMessageBuffer(builder);
// Create Mosaics
int[] mosaicBuffers = new int[mosaics.size()];
for (int i = 0; i < mosaics.size(); ++i) {
Mosaic mosaic = mosaics.get(i);
int id = MosaicBuffer.createIdVector(builder, UInt64.fromBigInteger(mosaic.getId().getId()));
int amount = MosaicBuffer.createAmountVector(builder, UInt64.fromBigInteger(mosaic.getAmount()));
MosaicBuffer.startMosaicBuffer(builder);
MosaicBuffer.addId(builder, id);
MosaicBuffer.addAmount(builder, amount);
mosaicBuffers[i] = MosaicBuffer.endMosaicBuffer(builder);
}
byte[] address = new Base32().decode(getRecipient().plain().getBytes(StandardCharsets.UTF_8));
// Create Vectors
int signatureVector = TransferTransactionBuffer.createSignatureVector(builder, new byte[64]);
int signerVector = TransferTransactionBuffer.createSignerVector(builder, new byte[32]);
int deadlineVector = TransferTransactionBuffer.createDeadlineVector(builder, UInt64.fromBigInteger(deadlineBigInt));
int feeVector = TransferTransactionBuffer.createFeeVector(builder, fee);
int recipientVector = TransferTransactionBuffer.createRecipientVector(builder, address);
int mosaicsVector = TransferTransactionBuffer.createMosaicsVector(builder, mosaicBuffers);
// replace by the all numbers sum or add a comment explaining this
int fixSize = 149;
TransferTransactionBuffer.startTransferTransactionBuffer(builder);
TransferTransactionBuffer.addSize(builder, fixSize + (16 * mosaics.size()) + bytePayload.length);
TransferTransactionBuffer.addSignature(builder, signatureVector);
TransferTransactionBuffer.addSigner(builder, signerVector);
TransferTransactionBuffer.addVersion(builder, version);
TransferTransactionBuffer.addType(builder, getType().getValue());
TransferTransactionBuffer.addFee(builder, feeVector);
TransferTransactionBuffer.addDeadline(builder, deadlineVector);
TransferTransactionBuffer.addRecipient(builder, recipientVector);
TransferTransactionBuffer.addNumMosaics(builder, mosaics.size());
TransferTransactionBuffer.addMessageSize(builder, bytePayload.length + 1);
TransferTransactionBuffer.addMessage(builder, message);
TransferTransactionBuffer.addMosaics(builder, mosaicsVector);
int codedTransfer = TransferTransactionBuffer.endTransferTransactionBuffer(builder);
builder.finish(codedTransfer);
return schema.serialize(builder.sizedByteArray());
}
Aggregations