exonum-java-binding
exonum-java-binding copied to clipboard
Add a prototype of TransactionConverter generator [ECR-3141]
Overview
See: https://jira.bf.local/browse/ECR-3141
Definition of Done
- [ ] There are no TODOs left in the code
- [ ] Change is covered by automated tests
- [ ] The coding guidelines are followed
- [ ] Public API has Javadoc
- [ ] Method preconditions are checked and documented in the Javadoc of the method
- [ ] Changelog is updated if needed (in case of notable or breaking changes)
- [ ] The continuous integration build passes
Effect on services is in https://github.com/exonum/exonum-java-binding/pull/858/commits/be74caeeed243cd27214d566ddadcd4bf64c9d6a; an example of autogenerated file see below:
AutoTransactionConverter.java
package com.example.auto;
import com.exonum.binding.cryptocurrency.transactions.CreateWalletTx;
import com.exonum.binding.cryptocurrency.transactions.TransferTx;
import com.exonum.binding.service.TransactionConverter;
import com.exonum.binding.transaction.RawTransaction;
import com.exonum.binding.transaction.Transaction;
import java.lang.IllegalArgumentException;
import java.lang.Override;
public final class AutoTransactionConverter implements TransactionConverter {
@Override
public Transaction toTransaction(RawTransaction rawTransaction) {
short txId = rawTransaction.getTransactionId();
switch (txId) {
case 1: return CreateWalletTx.fromRawTransaction(rawTransaction);
case 2: return TransferTx.fromRawTransaction(rawTransaction);
default: {
String errorMessage = String.format("Unknown transaction id (%d) in %s", txId, rawTransaction);
throw new IllegalArgumentException(errorMessage);
}
}
}
}