exonum-java-binding icon indicating copy to clipboard operation
exonum-java-binding copied to clipboard

Add a prototype of TransactionConverter generator [ECR-3141]

Open dmitry-timofeev opened this issue 6 years ago • 1 comments

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

dmitry-timofeev avatar Apr 24 '19 18:04 dmitry-timofeev

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);
      }
    }
  }
}

dmitry-timofeev avatar Apr 24 '19 18:04 dmitry-timofeev