Adapting for Ethereum as a library style:

+ API for submit transaction
This commit is contained in:
romanman 2014-09-08 10:12:22 +03:00
parent 979763106d
commit 7f8364bd0a
3 changed files with 59 additions and 2 deletions

View File

@ -1,12 +1,14 @@
package org.ethereum.facade;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.listener.EthereumListener;
import org.ethereum.net.client.ClientPeer;
import org.ethereum.net.client.PeerData;
import java.net.InetAddress;
import java.util.Set;
import java.util.concurrent.Future;
/**
* www.ethereumJ.com
@ -77,6 +79,36 @@ public interface Ethereum {
public void close();
/**
* Factory for general transaction
*
*
* @param nonce - account nonce, based on number of transaction submited by
* this account
* @param gasPrice - gas price bid by miner , the user ask can be based on
* lastr submited block
* @param gas - the quantity of gas requested for the transaction
* @param recieveAddress - the target address of the transaction
* @param value - the ether value of the transaction
* @param data - can be init procedure for creational transaction,
* also msg data for invoke transaction for only value
* transactions this one is empty.
* @return newly created transaction
*/
public Transaction createTransaction(byte[] nonce, byte[] gasPrice, byte[] gas,
byte[] recieveAddress, byte[] value, byte[] data );
/**
*
* @param transaction - submit transaction to the net, return
* option to wait for net return this transaction
* as approved
* @return
*/
public Future<Transaction> submitTransaction(Transaction transaction);
// 1. WorldManager.getInstance().getWallet();
// 2. // is blockchain still loading - if buffer is not empty

View File

@ -3,11 +3,15 @@ package org.ethereum.facade;
import java.net.InetAddress;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Future;
import org.ethereum.core.Transaction;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.client.ClientPeer;
import org.ethereum.net.client.PeerData;
import org.ethereum.net.submit.TransactionExecutor;
import org.ethereum.net.submit.TransactionTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -161,6 +165,27 @@ public class EthereumImpl implements Ethereum {
}
@Override
public Transaction createTransaction(byte[] nonce, byte[] gasPrice, byte[] gas,
byte[] recieveAddress, byte[] value, byte[] data ){
Transaction tx = new Transaction(nonce, gasPrice, gas,
recieveAddress, value, data);
return tx;
}
@Override
public Future<Transaction> submitTransaction(Transaction transaction){
TransactionTask transactionTask = new TransactionTask(transaction);
Future<Transaction> future = TransactionExecutor.instance.submitTransaction(transactionTask);
return future;
}
// public Future<Transaction> submitTransaction() -- wait for approve (like in wallet dialog)
}

View File

@ -35,8 +35,8 @@ public class DialogWorker extends SwingWorker<Transaction, Object> {
@Override
protected Transaction doInBackground() throws Exception {
TransactionTask transactionTask = new TransactionTask(tx);
Future<Transaction> future = TransactionExecutor.instance.submitTransaction(transactionTask);
Future<Transaction> future = UIEthereumManager.ethereum.submitTransaction(tx);
dialog.infoStatusMsg("Transaction sent to the network, waiting for approve");
try {