Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions core/src/blockchain/body_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::collections::{HashMap, HashSet};
use std::mem;
use std::sync::Arc;

use ctypes::transaction::ShardTransaction;
use kvdb::{DBTransaction, KeyValueDB};
use parking_lot::{Mutex, RwLock};
use primitives::{Bytes, H256};
Expand Down Expand Up @@ -347,9 +346,9 @@ fn transaction_address_entries(
parcel_hashes: impl IntoIterator<Item = UnverifiedTransaction>,
) -> impl Iterator<Item = TransactionHashAndAddress> {
parcel_hashes.into_iter().enumerate().filter_map(move |(parcel_index, parcel)| {
Option::<ShardTransaction>::from(parcel.action.clone()).map(|tx| {
parcel.tracker().map(|tracker| {
(
tx.tracker(),
tracker,
TransactionAddresses::new(TransactionAddress {
block_hash,
index: parcel_index,
Expand Down
30 changes: 30 additions & 0 deletions test/src/e2e/wrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ describe("WrapCCC", function() {
).to.be.rejected;
}).timeout(30_000);

it("WCCC tracker should return the corresponding transaction", async function() {
const wrapCCC = node.sdk.core.createWrapCCCTransaction({
shardId: 0,
recipient: await node.createP2PKHBurnAddress(),
quantity: 30,
payer: PlatformAddress.fromAccountId(faucetAccointId, {
networkId: "tc"
})
});
const seq = (await node.sdk.rpc.chain.getSeq(faucetAddress))!;
expect(seq).not.to.be.null;
const signedWrapCCC = wrapCCC.sign({
secret: faucetSecret,
seq,
fee: 10
});

const hash = await node.sdk.rpc.chain.sendSignedTransaction(
signedWrapCCC
);
const tracker = wrapCCC.tracker();

expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true;
expect(await node.sdk.rpc.chain.getTransactionByTracker(tracker)).not
.null;
expect(
await node.sdk.rpc.chain.getTransactionResultsByTracker(tracker)
).deep.equal([true]);
});

afterEach(async function() {
await node.clean();
});
Expand Down
24 changes: 21 additions & 3 deletions types/src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use primitives::H256;
use rlp::RlpStream;

use super::Action;
use super::ShardTransaction;
use super::{AssetWrapCCCOutput, ShardTransaction};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transaction {
Expand Down Expand Up @@ -52,8 +52,26 @@ impl Transaction {
}

pub fn tracker(&self) -> Option<H256> {
let t: Option<ShardTransaction> = self.action.clone().into();
t.map(|t| t.tracker())
let shard_tx = match self.action.clone() {
Action::WrapCCC {
shard_id,
lock_script_hash,
parameters,
quantity,
..
} => Some(ShardTransaction::WrapCCC {
network_id: self.network_id,
shard_id,
tx_hash: self.hash(),
output: AssetWrapCCCOutput {
lock_script_hash,
parameters,
quantity,
},
}),
other_actions => other_actions.into(),
};
shard_tx.map(|t| t.tracker())
}
pub fn is_master_key_allowed(&self) -> bool {
match self.action {
Expand Down