本文整理汇总了Java中org.ethereum.geth.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.ethereum.geth包,在下文中一共展示了Transaction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAndSendTransaction
import org.ethereum.geth.Transaction; //导入依赖的package包/类
/**
* Create and send transaction.
*
* @param passphrase Passphrase
* @param nonce Account nonce (use -1 to use last known nonce)
* @param toAddress Address destination
* @param amount Amount
* @param gasLimit Gas limit
* @param gasPrice Gas price
* @param data
* @param promise Promise
* @return Return String transaction
*/
@ReactMethod
public void createAndSendTransaction(String passphrase, double nonce, String toAddress,
double amount, double gasLimit, double gasPrice,
String data, Promise promise) {
try {
Account acc = GethHolder.getAccount();
Address fromAddress = acc.getAddress();
BigInt chain = new BigInt(GethHolder.getNodeConfig().getEthereumNetworkID());
Context ctx = new Context();
if (nonce == -1) {
nonce = GethHolder.getNode().getEthereumClient().getPendingNonceAt(ctx, fromAddress);
}
Transaction tx = new Transaction(
(long) nonce,
new Address(toAddress),
new BigInt((long) amount),
new BigInt((long) gasLimit),
new BigInt((long) gasPrice),
data.getBytes("UTF8"));
// Sign a transaction with a single authorization
Transaction signed = GethHolder.getKeyStore().signTxPassphrase(acc, passphrase, tx, chain);
// Send it out to the network.
GethHolder.getNode().getEthereumClient().sendTransaction(ctx, signed);
promise.resolve(tx.toString());
} catch (Exception e) {
promise.reject(NEW_TRANSACTION_ERROR, e);
}
}
示例2: signTransaction
import org.ethereum.geth.Transaction; //导入依赖的package包/类
@Override
public Single<byte[]> signTransaction(Wallet signer, String signerPassword, String toAddress, BigInteger amount, BigInteger gasPrice, BigInteger gasLimit, long nonce, byte[] data, long chainId) {
return Single.fromCallable(() -> {
BigInt value = new BigInt(0);
value.setString(amount.toString(), 10);
BigInt gasPriceBI = new BigInt(0);
gasPriceBI.setString(gasPrice.toString(), 10);
BigInt gasLimitBI = new BigInt(0);
gasLimitBI.setString(gasLimit.toString(), 10);
Transaction tx = new Transaction(
nonce,
new Address(toAddress),
value,
gasLimitBI,
gasPriceBI,
data);
BigInt chain = new BigInt(chainId); // Chain identifier of the main net
org.ethereum.geth.Account gethAccount = findAccount(signer.address);
keyStore.unlock(gethAccount, signerPassword);
Transaction signed = keyStore.signTx(gethAccount, tx, chain);
keyStore.lock(gethAccount.getAddress());
return signed.encodeRLP();
})
.subscribeOn(Schedulers.io());
}
示例3: initGame
import org.ethereum.geth.Transaction; //导入依赖的package包/类
@OnClick(R.id.init_game)
void initGame() {
// machine
// .initGameForPlayer(new Uint256(Convert.toWei(0.001, Convert.Unit.ETHER)), new Uint256(20))
// .map(receipt -> machine.getGameInitializedEvents(receipt))
// .subscribe(gameInitializedEventResponses -> {
// if (gameInitializedEventResponses.isEmpty()) {
// Log.i(TAG, "response is empty");
// return;
// }
// SlotMachine.GameInitializedEventResponse response = gameInitializedEventResponses.get(0);
//
// Log.i(TAG, "player address : " + response.player.toString());
// Log.i(TAG, "bet : " + response.bet.getValue());
// Log.i(TAG, "lines : " + response.lines.getValue());
// });
Completable
.create(e -> {
CredentialManager.setDefault(1, "asdf");
Function function = new Function(
"initGameForPlayer",
Arrays.asList(
new Uint256(Convert.toWei(0.001, Convert.Unit.ETHER)),
new Uint256(20),
new Uint256(playerSeed.getIndex())),
Collections.emptyList());
Transaction tx = new Transaction(
playerNonce++, // nonce
new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
new BigInt(0),
Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
Utils.hexToByte(FunctionEncoder.encode(function))
);
Transaction signed = CredentialManager.getDefault().sign(tx);
GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);
e.onComplete();
})
.subscribeOn(Schedulers.io())
.subscribe(() -> {
}, Throwable::printStackTrace);
}
示例4: setBankerSeed
import org.ethereum.geth.Transaction; //导入依赖的package包/类
@OnClick(R.id.set_banker_seed)
void setBankerSeed() {
// machine
// .setBankerSeed(new Bytes32(Utils.generateRandom(bankerSeed, banker--)))
// .map(receipt -> machine.getBankerSeedSetEvents(receipt))
// .subscribe(bankerSeedSetEventResponses -> {
// if (bankerSeedSetEventResponses.isEmpty()) {
// Log.i(TAG, "response is empty");
// return;
// }
//
// SlotMachine.BankerSeedSetEventResponse response = bankerSeedSetEventResponses.get(0);
//
// Log.i(TAG, "banker seed : " + Utils.byteToHex(response.bankerSeed.getValue()));
// });
Completable
.create(e -> {
CredentialManager.setDefault(0, "asdf");
Function function = new Function(
"setBankerSeed",
Arrays.asList(
bankerSeed.getSeed(playerSeed.getIndex()),
new Uint256(playerSeed.getIndex())),
Collections.emptyList());
Transaction tx = new Transaction(
bankerNonce++, // nonce
new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
new BigInt(0),
Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
Utils.hexToByte(FunctionEncoder.encode(function))
);
Transaction signed = CredentialManager.getDefault().sign(tx);
GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);
e.onComplete();
})
.subscribeOn(Schedulers.io())
.subscribe(() -> {
}, Throwable::printStackTrace);
}
示例5: setPlayerSeed
import org.ethereum.geth.Transaction; //导入依赖的package包/类
@OnClick(R.id.set_player_seed)
void setPlayerSeed() {
// machine
// .setPlayerSeed(new Bytes32(Utils.generateRandom(playerSeed, player--)))
// .map(receipt -> machine.getGameConfirmedEvents(receipt))
// .subscribe(gameConfirmedEventResponses -> {
// if (gameConfirmedEventResponses.isEmpty()) {
// Log.i(TAG, "response is empty");
// return;
// }
//
// SlotMachine.GameConfirmedEventResponse response = gameConfirmedEventResponses.get(0);
//
// Log.i(TAG, "reward : " + response.reward.getValue());
// });
Completable
.create(e -> {
CredentialManager.setDefault(1, "asdf");
Function function = new Function(
"setPlayerSeed",
Arrays.asList(
playerSeed.getSeed(),
new Uint256(playerSeed.getIndex())),
Collections.emptyList());
Transaction tx = new Transaction(
playerNonce++, // nonce
new org.ethereum.geth.Address(machine.getContractAddress()), // receiver address
new BigInt(0),
Convert.toBigInt(GethConstants.DEFAULT_GAS_LIMIT), // gas limit
Convert.toBigInt(GethConstants.DEFAULT_GAS_PRICE), // gas price
Utils.hexToByte(FunctionEncoder.encode(function))
);
Transaction signed = CredentialManager.getDefault().sign(tx);
GethManager.getClient().sendTransaction(GethManager.getMainContext(), signed);
bankerSeed.confirm(playerSeed.getIndex());
playerSeed.confirm(playerSeed.getIndex());
e.onComplete();
})
.subscribeOn(Schedulers.io())
.subscribe(() -> {
}, Throwable::printStackTrace);
}