use of neo.model.core.Transaction in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getTransactionWithAccountList.
@Override
public List<Transaction> getTransactionWithAccountList(final UInt160 account) {
final List<Transaction> transactionList = new ArrayList<>();
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
boolean transactionHasAccount = false;
for (final TransactionOutput output : transaction.outputs) {
if (output.scriptHash.equals(account)) {
transactionHasAccount = true;
}
}
if (transactionHasAccount) {
transactionList.add(transaction);
}
}
}
return transactionList;
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class AbstractJsonMockBlockDb method getTransactionWithHash.
@Override
public final Transaction getTransactionWithHash(final UInt256 hash) {
final JSONArray mockBlockDb = getMockBlockDb();
for (int ix = 0; ix < mockBlockDb.length(); ix++) {
final JSONObject mockBlock = mockBlockDb.getJSONObject(ix);
final Block block = getBlock(mockBlock, true);
for (final Transaction transaction : block.getTransactionList()) {
if (transaction.getHash().equals(hash)) {
return transaction;
}
}
}
throw new RuntimeException("no transaction with hash:" + hash);
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class MockUtil method getMockBlock001.
public static Block getMockBlock001() {
final Block block = getMockBlock000();
final Transaction transaction = getMockTransaction000();
transaction.inputs.add(getCoinReference000());
transaction.outputs.add(getTransactionOutput000());
transaction.scripts.add(getWitness000());
block.getTransactionList().add(transaction);
return block;
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class TestBlockSerialization method test00ZAllBlocks.
/**
* pulls all the blocks (slow) to check for full coverage.
*
* @throws ClientProtocolException
* if an error occurs.
* @throws IOException
* if an error occurs.
* @throws DecoderException
* if an error occurs.
* @throws InterruptedException
* if an error occurs.
*/
@Test
@Ignore
public void test00ZAllBlocks() throws ClientProtocolException, IOException, DecoderException, InterruptedException {
final BlockDb blockDb = new AbstractJsonMockBlockDb() {
@Override
public JSONArray getMockBlockDb() {
return new JSONArray();
}
};
final long maxBlockIx = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
final Set<TransactionType> knownTypeSet = new TreeSet<>();
for (long blockIx = 0; blockIx <= maxBlockIx; blockIx++) {
final Block block = blockDb.getFullBlockFromHeight(blockIx);
for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
final Transaction tx = block.getTransactionList().get(txIx);
if (!knownTypeSet.contains(tx.type)) {
LOG.error("getBlock {} {} tx {} {}", block.getIndexAsLong(), block.prevHash, txIx, tx.type);
knownTypeSet.add(tx.type);
}
}
}
blockDb.close();
}
use of neo.model.core.Transaction in project neo-java by coranos.
the class TestCoreToJson method test011Transaction.
/**
* test Transaction.
*/
@Test
public void test011Transaction() {
final Transaction transaction = MockUtil.getMockTransaction000();
final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test011Transaction");
final String expectedStr = new JSONObject(expectedStrRaw).toString();
final String actualStr = transaction.toString();
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
final String expectedHexStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test011TransactionHex");
final String expectedHexStr = new JSONObject(expectedHexStrRaw).toString();
final String actualHexStr = TestUtil.toHexJsonObject(ModelUtil.toHexString(transaction.toByteArray())).toString();
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedHexStr, actualHexStr);
}
Aggregations