Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem:(CRO-557) no way to import transactions (without a view key) #695

Merged
merged 1 commit into from
Dec 27, 2019

Conversation

linfeng-crypto
Copy link
Contributor

@linfeng-crypto linfeng-crypto commented Dec 17, 2019

solution:

  • add a interface export_tx for sender to get the plain transaction
  • add a interface import_tx for receiver to import the plain transaction and get the output UTXO

@codecov
Copy link

codecov bot commented Dec 17, 2019

Codecov Report

Merging #695 into master will decrease coverage by 0.55%.
The diff coverage is 8.21%.

@@            Coverage Diff             @@
##           master     #695      +/-   ##
==========================================
- Coverage   69.71%   69.16%   -0.56%     
==========================================
  Files         131      131              
  Lines       16745    16886     +141     
==========================================
+ Hits        11674    11679       +5     
- Misses       5071     5207     +136
Impacted Files Coverage Δ
client-common/src/lib.rs 100% <ø> (ø) ⬆️
chain-core/src/tx/data/input.rs 23.52% <0%> (-3.14%) ⬇️
client-core/src/wallet/default_wallet_client.rs 42.73% <0%> (-11.62%) ⬇️
client-common/src/transaction.rs 50% <0%> (-4.06%) ⬇️
...builder/unauthorized_wallet_transaction_builder.rs 0% <0%> (ø) ⬆️
client-core/src/service/wallet_service.rs 85.11% <0%> (-3.16%) ⬇️
...tion_builder/default_wallet_transaction_builder.rs 88.58% <0%> (-2.93%) ⬇️
client-cli/src/command/transaction_command.rs 0% <0%> (ø) ⬆️
client-rpc/src/rpc/wallet_rpc.rs 63.24% <0%> (-1.48%) ⬇️
client-core/src/wallet/syncer.rs 60.77% <100%> (+0.56%) ⬆️
... and 3 more

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good (I haven't tested it yet though), just a bit more descriptive comments would be helpful + as this is a bigger feature, it'll be good to update CHANGELOG.md that this feature was added (just put a note at the top with a header ## v0.1.1 (unreleased) )

@@ -185,6 +185,9 @@ pub trait WalletClient: Send + Sync {

/// Broadcasts a transaction to Crypto.com Chain
fn broadcast_transaction(&self, tx_aux: &TxAux) -> Result<BroadcastTxResponse>;

/// Get the plain transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment just repeats the name, so not that helpful -- it'd be better to include some information that one can't read from the type signature... e.g. under what circumstances it could fail or what kind of String it returns (it seems to return base64-encoded ?)

pub struct TransactionInfo {
/// enum Transaction type
pub tx: Transaction,
/// block height of the tx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess block height when the transaction was committed?

Comment on lines 116 to 127
about = "Download a plain transaction by a given transaction id"
)]
DownloadTx {
#[structopt(name = "name", short, long, help = "Name of wallet")]
name: String,
#[structopt(name = "tx_id", short, long, help = "transaction id")]
tx_id: String,
},

#[structopt(
name = "sync_tx",
about = "Synchronize a plain transaction that view key not included"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in about, it may good to list the transaction types this applies to

Copy link
Collaborator

@leejw51crypto leejw51crypto Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also how about
./client-cli transaction download --name a
sub-command of transaction

download_tx is too long to type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think so.

@leejw51crypto
Copy link
Collaborator

overall, lgtm,
could you add some unit-test?

@@ -29,4 +30,8 @@ impl WalletTransactionBuilder for UnauthorizedWalletTransactionBuilder {
fn obfuscate(&self, _: SignedTransaction) -> Result<TxAux> {
Err(ErrorKind::PermissionDenied.into())
}

fn decrypt_tx(&self, _txid: TxId, _private_key: &PrivateKey) -> Result<Transaction> {
Copy link
Collaborator

@yihuang yihuang Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only two methods of trait TransactionObfuscation get re-exported by trait WalletTransactionBuilder, it doesn't feel right ;D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if I don't use the WalletTransactionBuilder, I have to put a TransactionObfuscation implied object into the DefaultWalletClient and I have to deal with the new_read_only function where I have to create a new mock transaction obfuscation like UnauthorizedObfuscation and make impl the TransactionObfuscation, which is much expensive.

@@ -374,6 +381,52 @@ impl<'a, S: SecureStorage, C: Client, D: TxDecryptor> WalletSyncerImpl<'a, S, C,
Ok(())
}

fn sync_tx(&mut self, tx_str: &str) -> Result<Coin> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is perfectly ok to write as a separate function, it's not "sync".

spent_flags?,
)
.chain(|| (ErrorKind::InvalidInput, "import error"))?;
self.save(&memento)?;
Copy link
Collaborator

@yihuang yihuang Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the side-effect of implementing this feature in Syncer, save will also write SyncState which is not used by this feature, but if there is concurrently running syncing process, it will override data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make an individual function called update_status and use it in save

}

/// update WalletStateMemento when import a transaction
pub(crate) fn import_transaction(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename syncer_logic to wallet_logic or something when it's function goes beyond syncing, to prevent future confusion.

@@ -64,6 +64,9 @@ pub trait WalletRpc: Send + Sync {

#[rpc(name = "wallet_transactions")]
fn transactions(&self, request: WalletRequest) -> Result<Vec<TransactionChange>>;

#[rpc(name = "wallet_downloadTransaction")]
fn plain_transaction(&self, request: WalletRequest, txid: String) -> Result<String>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about sync_tx -> importTransaction, downloadTransaction -> exportTransaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@tomtau tomtau self-requested a review December 19, 2019 09:23
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some merge conflicts with master

CHANGELOG.md Outdated
Comment on lines 8 to 11
## v0.1.1

### Features
* *client*: export and import transaction -- transaction in which the receiver's view key not included can be exported by a give transaction id (the sender can list transactions and find it), getting a base64 encoded plain transaction string and the receiver can import the string into wallet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master is already unreleased 0.2, so perhaps no "0.1.1", just move the features paragraph under 0.2

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems it fails to compile after merges

@tomtau tomtau self-requested a review December 20, 2019 03:18
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks all right -- can you squash the commits?

the build fail is now due to clippy changes -- I fixed it in f3eed40 so don't worry about that

@tomtau
Copy link
Contributor

tomtau commented Dec 20, 2019

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 20, 2019

This PR was included in a batch with a merge conflict, it will be automatically retried

@bors
Copy link
Contributor

bors bot commented Dec 20, 2019

Merge conflict

solution:
- add a interface `export_tx` for sender to download the the transaction
- add a interface `import_tx` for receiver to import the transaction and get the output UTXO
@devashishdxt
Copy link
Collaborator

bors r+

bors bot added a commit that referenced this pull request Dec 27, 2019
695: Problem:(CRO-557) no way to import transactions (without a view key) r=devashishdxt a=linfeng-crypto

solution:
- add a interface `export_tx` for sender to get the plain transaction
- add a interface `import_tx` for receiver to import the plain transaction and get the output UTXO


740: Problem:(CRO-661) not enough logging in debug enclave execution r=devashishdxt a=linfeng-crypto

solution: add some logs.

Co-authored-by: linfeng <linfeng@crypto.com>
@bors
Copy link
Contributor

bors bot commented Dec 27, 2019

Build failed (retrying...)

bors bot added a commit that referenced this pull request Dec 27, 2019
695: Problem:(CRO-557) no way to import transactions (without a view key) r=devashishdxt a=linfeng-crypto

solution:
- add a interface `export_tx` for sender to get the plain transaction
- add a interface `import_tx` for receiver to import the plain transaction and get the output UTXO


Co-authored-by: linfeng <linfeng@crypto.com>
@bors
Copy link
Contributor

bors bot commented Dec 27, 2019

@bors bors bot merged commit 91afe97 into crypto-com:master Dec 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants