本文整理汇总了Java中org.ethereum.core.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.ethereum.core包,在下文中一共展示了Transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isValid
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Override
public boolean isValid(Block block, Block parent) {
if (block == null) {
logger.warn("BlockTxsFieldsValidationRule - block is null");
return false;
}
List<Transaction> txs = block.getTransactionsList();
for (Transaction tx : txs) {
try {
tx.verify();
} catch (RuntimeException e) {
logger.warn("Unable to verify transaction", e);
return false;
}
}
return true;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:20,代码来源:BlockTxsFieldsValidationRule.java
示例2: runCreate01Resource
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/create01.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx01");
Assert.assertNotNull(transaction);
TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash());
Assert.assertNotNull(txinfo);
BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());
Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
// According to TestRPC and geth, the gas used is 0x010c2d
Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:DslFilesTest.java
示例3: removeNonce
import org.ethereum.core.Transaction; //导入依赖的package包/类
void removeNonce(BigInteger nonce) {
List<Transaction> newlist = new LinkedList<>();
for (Transaction tx : this.txs) {
if (new BigInteger(1, tx.getNonce()).compareTo(nonce) == 0) {
continue;
}
newlist.add(tx);
}
this.txs = newlist;
if (newlist.isEmpty()) {
this.nextNonce = null;
}
}
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:TxsPerAccount.java
示例4: cleanOldTxsAndTxsPerAccountTest
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void cleanOldTxsAndTxsPerAccountTest() {
long time = System.currentTimeMillis();
final long threshold = 300001;
Random random = new Random(0);
Transaction tx1 = Tx.create(0, 0, 0, 0, 0, 0, random);
Map<String, TxTimestamp> knownTxs = new HashMap<>();
Map<RskAddress, TxsPerAccount> txsPerAccounts = new HashMap<>();
knownTxs.put("2", new TxTimestamp(tx1, time - threshold));
TxsPerAccount tpa = new TxsPerAccount();
tpa.getTransactions().add(tx1);
txsPerAccounts.put(tx1.getSender(), tpa);
TxHandlerImpl txHandler = new TxHandlerImpl(ConfigHelper.CONFIG);
txHandler.setKnownTxs(knownTxs);
txHandler.setTxsPerAccounts(txsPerAccounts);
txHandler.cleanOldTxs();
Assert.assertTrue(txHandler.getKnownTxs().isEmpty());
Assert.assertTrue(txHandler.getTxsPerAccounts().isEmpty());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:TxHandlerTest.java
示例5: retrieveTransactionsReadyToBeSendTwoNonces
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void retrieveTransactionsReadyToBeSendTwoNonces() {
TxsPerAccount txspa = new TxsPerAccount();
Transaction tx = buildTransaction(1);
Transaction tx2 = buildTransaction(2);
txspa.getTransactions().add(tx);
txspa.getTransactions().add(tx2);
List<Transaction> txs = txspa.readyToBeSent(BigInteger.ONE);
Assert.assertNotNull(txs);
Assert.assertFalse(txs.isEmpty());
Assert.assertEquals(2, txs.size());
Assert.assertEquals(tx, txs.get(0));
Assert.assertEquals(tx2, txs.get(1));
Assert.assertNotNull(txspa.getNextNonce());
Assert.assertEquals(BigInteger.valueOf(3), txspa.getNextNonce());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:TxsPerAccountTest.java
示例6: onBlock
import org.ethereum.core.Transaction; //导入依赖的package包/类
/**
* For each block we are looking for our transactions and clearing them
* The actual receiver balance is confirmed upon block arrival
*/
public void onBlock(Block block, List<TransactionReceipt> receipts) {
int cleared = 0;
for (Transaction tx : block.getTransactionsList()) {
ByteArrayWrapper txHash = new ByteArrayWrapper(tx.getHash());
Transaction ptx = pendingTxs.get(txHash);
if (ptx != null) {
logger.info(" - Pending transaction cleared 0x" + Hex.toHexString(tx.getHash()).substring(0, 8) +
" in block " + block.getShortDescr());
pendingTxs.remove(txHash);
cleared++;
}
}
BigInteger receiverBalance = ethereum.getRepository().getBalance(receiverAddress);
BigInteger receiverBalancePending = pendingState.getRepository().getBalance(receiverAddress);
logger.info("" + cleared + " transactions cleared in the block " + block.getShortDescr());
logger.info("Receiver pending/current balance: " + receiverBalancePending + " / " + receiverBalance +
" (" + pendingTxs.size() + " pending txs)");
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:PendingStateSample.java
示例7: setLockWhitelistDisableBlockDelay
import org.ethereum.core.Transaction; //导入依赖的package包/类
/**
* Sets a delay in the BTC best chain to disable lock whitelist
* @param tx current RSK transaction
* @param disableBlockDelayBI block since current BTC best chain height to disable lock whitelist
* @return 1 if it was successful, -1 if a delay was already set, -2 if disableBlockDelay contains an invalid value
*/
public Integer setLockWhitelistDisableBlockDelay(Transaction tx, BigInteger disableBlockDelayBI) {
if (!isLockWhitelistChangeAuthorized(tx)) {
return LOCK_WHITELIST_GENERIC_ERROR_CODE;
}
LockWhitelist lockWhitelist = provider.getLockWhitelist();
if (lockWhitelist.isDisableBlockSet()) {
return -1;
}
int disableBlockDelay = disableBlockDelayBI.intValueExact();
int bestChainHeight = btcBlockChain.getBestChainHeight();
if (bestChainHeight < 0 || Integer.MAX_VALUE - disableBlockDelay < bestChainHeight) {
return -2;
}
lockWhitelist.setDisableBlockHeight(bestChainHeight + disableBlockDelay);
return 1;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:BridgeSupport.java
示例8: balanceIsNotValidatedIfFreeTx
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void balanceIsNotValidatedIfFreeTx() {
Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(),
BigInteger.ONE.toByteArray(),
BigInteger.valueOf(21071).toByteArray(),
new ECKey().getAddress(),
BigInteger.ZERO.toByteArray(),
Hex.decode("0001"),
ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getChainId());
tx.sign(new ECKey().getPrivKeyBytes());
TxValidatorAccountBalanceValidator tv = new TxValidatorAccountBalanceValidator();
Assert.assertTrue(tv.validate(tx, new AccountState(BigInteger.ZERO, BigInteger.ZERO), BigInteger.ONE, BigInteger.ONE, Long.MAX_VALUE, true));
}
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:TxValidatorAccountBalanceValidatorTest.java
示例9: processCommand
import org.ethereum.core.Transaction; //导入依赖的package包/类
private void processCommand(DslCommand cmd) throws DslProcessorException {
if (cmd.isCommand("parent"))
this.builder.parent(this.world.getBlockByName(cmd.getArgument(0)));
else if (cmd.isCommand("build"))
this.world.saveBlock(this.name, this.builder.build());
else if (cmd.isCommand("uncles")) {
List<BlockHeader> uncles = new ArrayList<>();
for (int k = 0; k < cmd.getArity(); k++)
uncles.add(this.world.getBlockByName(cmd.getArgument(k)).getHeader());
this.builder.uncles(uncles);
}
else if (cmd.isCommand("transactions")) {
List<Transaction> transactions = new ArrayList<>();
for (int k = 0; k < cmd.getArity(); k++)
transactions.add(this.world.getTransactionByName(cmd.getArgument(k)));
this.builder.transactions(transactions);
}
else
throw new DslProcessorException(String.format("Unknown command '%s'", cmd.getVerb()));
}
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BlockBuildDslProcessor.java
示例10: TransactionResultDTO
import org.ethereum.core.Transaction; //导入依赖的package包/类
public TransactionResultDTO (Block b, Integer index, Transaction tx) {
hash = TypeConverter.toJsonHex(tx.getHash());
if (Arrays.equals(tx.getNonce(), ByteUtil.EMPTY_BYTE_ARRAY)) {
nonce = "0";
} else {
nonce = TypeConverter.toJsonHex(tx.getNonce());
}
blockHash = b != null ? TypeConverter.toJsonHex(b.getHash()) : null;
blockNumber = b != null ? TypeConverter.toJsonHex(b.getNumber()) : null;
transactionIndex = index != null ? TypeConverter.toJsonHex(index) : null;
from= TypeConverter.toJsonHex(tx.getSender().getBytes());
to = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
gas = TypeConverter.toJsonHex(tx.getGasLimit()); // Todo: unclear if it's the gas limit or gas consumed what is asked
gasPrice = TypeConverter.toJsonHex(tx.getGasPrice());
if (Arrays.equals(tx.getValue(), ByteUtil.EMPTY_BYTE_ARRAY)) {
value = "0";
} else {
value = TypeConverter.toJsonHex(tx.getValue());
}
input = TypeConverter.toJsonHex(tx.getData());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:TransactionResultDTO.java
示例11: buildTransaction
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void buildTransaction() {
Account sender = new AccountBuilder().name("sender").build();
Account receiver = new AccountBuilder().name("receiver").build();
Transaction tx = new TransactionBuilder()
.sender(sender)
.receiver(receiver)
.value(BigInteger.TEN)
.nonce(2)
.build();
Assert.assertNotNull(tx);
Assert.assertArrayEquals(sender.getAddress().getBytes(), tx.getSender().getBytes());
Assert.assertArrayEquals(receiver.getAddress().getBytes(), tx.getReceiveAddress().getBytes());
Assert.assertEquals(BigInteger.TEN, new BigInteger(1, tx.getValue()));
Assert.assertEquals(BigInteger.ONE, new BigInteger(1, tx.getGasPrice()));
Assert.assertEquals(BigInteger.valueOf(2), new BigInteger(1, tx.getNonce()));
Assert.assertEquals(BigInteger.valueOf(21000), new BigInteger(1, tx.getGasLimit()));
Assert.assertNotNull(tx.getData());
Assert.assertEquals(0, tx.getData().length);
}
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:TransactionBuilderTest.java
示例12: build
import org.ethereum.core.Transaction; //导入依赖的package包/类
public static Block build(BlockHeaderTck header,
List<TransactionTck> transactionsTck,
List<BlockHeaderTck> unclesTck) {
if (header == null) return null;
List<BlockHeader> uncles = new ArrayList<>();
if (unclesTck != null) for (BlockHeaderTck uncle : unclesTck)
uncles.add(BlockHeaderBuilder.build(uncle));
List<Transaction> transactions = new ArrayList<>();
if (transactionsTck != null) for (TransactionTck tx : transactionsTck)
transactions.add(TransactionBuilder.build(tx));
BlockHeader blockHeader = BlockHeaderBuilder.build(header);
Block block = new Block(
blockHeader,
transactions, uncles);
return block;
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:22,代码来源:BlockBuilder.java
示例13: broadcastTransaction
import org.ethereum.core.Transaction; //导入依赖的package包/类
/**
* broadcastTransaction Propagates a transaction message across active peers with exclusion of
* the peers with an id belonging to the skip set.
*
* @param transaction new Transaction to be sent
* @param skip the set of peers to avoid sending the message.
* @return a set containing the ids of the peers that received the transaction.
*/
@Nonnull
public Set<NodeID> broadcastTransaction(@Nonnull final Transaction transaction, @Nullable final Set<NodeID> skip) {
Metrics.broadcastTransaction(transaction);
List<Transaction> transactions = new ArrayList<>();
transactions.add(transaction);
final Set<NodeID> res = new HashSet<>();
final EthMessage newTransactions = new RskMessage(config, new TransactionsMessage(transactions));
synchronized (activePeers) {
final Vector<Channel> peers = activePeers.values().stream()
.filter(p -> skip == null || !skip.contains(new NodeID(p.getNodeId())))
.collect(Collectors.toCollection(() -> new Vector<>()));
for (Channel peer : peers) {
res.add(new NodeID(peer.getNodeId()));
peer.sendMessage(newTransactions);
}
}
return res;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:ChannelManagerImpl.java
示例14: web3_LogFilterElement_toString
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void web3_LogFilterElement_toString() {
LogInfo logInfo = Mockito.mock(LogInfo.class);
Mockito.when(logInfo.getData()).thenReturn(new byte[]{1});
List<DataWord> topics = new ArrayList<>();
topics.add(new DataWord("c1"));
topics.add(new DataWord("c2"));
Mockito.when(logInfo.getTopics()).thenReturn(topics);
Block block = Mockito.mock(Block.class);
Mockito.when(block.getHash()).thenReturn(new byte[]{1});
Mockito.when(block.getNumber()).thenReturn(1L);
int txIndex = 1;
Transaction tx = Mockito.mock(Transaction.class);
Mockito.when(tx.getHash()).thenReturn(new byte[]{2});
int logIdx = 5;
LogFilterElement logFilterElement = new LogFilterElement(logInfo, block, txIndex, tx, logIdx);
Assert.assertEquals(logFilterElement.toString(), "LogFilterElement{logIndex='0x5', blockNumber='0x1', blockHash='0x01', transactionHash='0x02', transactionIndex='0x1', address='0x00', data='0x01', topics=[0x00000000000000000000000000000000000000000000000000000000000000c1, 0x00000000000000000000000000000000000000000000000000000000000000c2]}");
}
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:Web3RskImplTest.java
示例15: invalidGasPriceTransactionTest
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void invalidGasPriceTransactionTest() {
Transaction tx = Tx.create(0, 50000, 1, 0, 0, 0, new Random(0));
List<Transaction> txs = new LinkedList<>();
txs.add(tx);
Map<RskAddress, BigInteger> accountNounces = new HashMap();
byte[] addressBytes = ByteUtil.leftPadBytes(BigInteger.valueOf(new Random(0).nextLong()).toByteArray(), 20);
accountNounces.put(new RskAddress(addressBytes), BigInteger.valueOf(0));
Repository repository = Mockito.mock(Repository.class);
BigInteger minGasPrice = BigInteger.valueOf(2);
LinkedList<Transaction> txsToRemove = new LinkedList<>();
List<Transaction> res = new MinerUtils().filterTransactions(txsToRemove, txs, accountNounces, repository, minGasPrice);
Assert.assertEquals(0, res.size());
Assert.assertEquals(1, txsToRemove.size());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:MinerUtilsTest.java
示例16: sendTransaction
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Override
public synchronized String sendTransaction(Web3.CallArguments args) {
Account account = this.getAccount(args.from);
String s = null;
try {
if (account == null) {
throw new JsonRpcInvalidParamException("From address private key could not be found in this node");
}
String toAddress = args.to != null ? Hex.toHexString(stringHexToByteArray(args.to)) : null;
BigInteger value = args.value != null ? TypeConverter.stringNumberAsBigInt(args.value) : BigInteger.ZERO;
BigInteger gasPrice = args.gasPrice != null ? TypeConverter.stringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO;
BigInteger gasLimit = args.gas != null ? TypeConverter.stringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION_DEFAULT);
if (args.data != null && args.data.startsWith("0x")) {
args.data = args.data.substring(2);
}
synchronized (pendingState) {
BigInteger accountNonce = args.nonce != null ? TypeConverter.stringNumberAsBigInt(args.nonce) : (pendingState.getRepository().getNonce(account.getAddress().getBytes()));
Transaction tx = Transaction.create(config, toAddress, value, accountNonce, gasPrice, gasLimit, args.data);
tx.sign(account.getEcKey().getPrivKeyBytes());
eth.submitTransaction(tx.toImmutableTransaction());
s = TypeConverter.toJsonHex(tx.getHash());
}
return s;
} finally {
LOGGER.debug("eth_sendTransaction({}): {}", args, s);
}
}
开发者ID:rsksmart,项目名称:rskj,代码行数:32,代码来源:EthModuleWalletEnabled.java
示例17: cleanOldTxsTest
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void cleanOldTxsTest() {
long time = System.currentTimeMillis();
final long threshold = 300001;
Random random = new Random(0);
Transaction tx1 = Tx.create(0, 0, 0, 0, 0, 0, random);
Transaction tx2 = Tx.create(0, 0, 0, 1, 0, 0, random);
Map<String, TxTimestamp> knownTxs = new HashMap<>();
Map<RskAddress, TxsPerAccount> txsPerAccounts = new HashMap<>();
knownTxs.put("1", new TxTimestamp(tx1, time));
knownTxs.put("2", new TxTimestamp(tx1, time - threshold));
TxsPerAccount tpa = new TxsPerAccount();
tpa.getTransactions().add(tx1);
tpa.getTransactions().add(tx2);
txsPerAccounts.put(tx1.getSender(), tpa);
TxHandlerImpl txHandler = new TxHandlerImpl(ConfigHelper.CONFIG);
txHandler.setKnownTxs(knownTxs);
txHandler.setTxsPerAccounts(txsPerAccounts);
txHandler.cleanOldTxs();
Assert.assertEquals(1, txHandler.getKnownTxs().keySet().size());
Assert.assertEquals(1, txHandler.getTxsPerAccounts().entrySet().iterator().next().getValue().getTransactions().size());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:TxHandlerTest.java
示例18: broadcastTransaction
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Nonnull
@Override
public Set<NodeID> broadcastTransaction(@Nonnull Transaction transaction, @Nullable Set<NodeID> skip) {
this.transactions.add(transaction);
this.lastSkip = skip;
return new HashSet<>();
}
开发者ID:rsksmart,项目名称:rskj,代码行数:8,代码来源:SimpleChannelManager.java
示例19: addTwiceAndGetPendingTransaction
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void addTwiceAndGetPendingTransaction() {
PendingStateImpl pendingState = createSampleNewPendingState();
Transaction tx = createSampleTransaction();
pendingState.addPendingTransaction(tx);
pendingState.addPendingTransaction(tx);
List<Transaction> transactions = pendingState.getPendingTransactions();
Assert.assertNotNull(transactions);
Assert.assertFalse(transactions.isEmpty());
Assert.assertEquals(1, transactions.size());
Assert.assertTrue(transactions.contains(tx));
}
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:PendingStateImplTest.java
示例20: setAndGetTransactions
import org.ethereum.core.Transaction; //导入依赖的package包/类
@Test
public void setAndGetTransactions() {
List<Transaction> txs = TransactionUtils.getTransactions(10);
TransactionsMessage message = new TransactionsMessage(txs);
Assert.assertNotNull(message.getTransactions());
Assert.assertEquals(10, message.getTransactions().size());
Assert.assertSame(txs, message.getTransactions());
}
开发者ID:rsksmart,项目名称:rskj,代码行数:10,代码来源:TransactionsMessageTest.java
注:本文中的org.ethereum.core.Transaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论