Skip to content

Commit

Permalink
Withdraw to the specified address possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenKor committed Apr 4, 2022
1 parent 4f0f709 commit be15e06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
18 changes: 11 additions & 7 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,19 @@ s
return await this.zpClient.waitJobCompleted(TOKEN_ADDRESS, jobId);
}

public async withdrawShielded(amount: string): Promise<string> {
public async withdrawShielded(amount: string, external_addr: string): Promise<string> {

let address = null;
if (isEvmBased(NETWORK)) {
address = await this.client.getAddress();
}

if (isSubstrateBased(NETWORK)) {
address = await this.client.getPublicKey();
if (external_addr == null) {
if (isEvmBased(NETWORK)) {
address = await this.client.getAddress();
}

if (isSubstrateBased(NETWORK)) {
address = await this.client.getPublicKey();
}
} else {
address = external_addr;
}

console.log('Making withdraw...');
Expand Down
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export async function depositShielded(amount: string) {
this.echo(`Done [txHash: ${txHash}]`);
}

export async function withdrawShielded(amount: string) {
export async function withdrawShielded(amount: string, address: string) {
this.echo('Performing shielded withdraw...');
this.pause();
const txHash = await this.account.withdrawShielded(amount);
const txHash = await this.account.withdrawShielded(amount, address);
this.resume();
this.echo(`Done [txHash: ${txHash}]`);
}
Expand Down
26 changes: 13 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ const COMMANDS: { [key: string]: [(...args) => void, string, string] } = {
'set-seed': [c.setSeed, '<seed phrase> <password>', 'replace the seed phrase for the current account'],
'get-seed': [c.getSeed, '<password>', 'print the seed phrase for the current account'],
'gen-seed': [c.genSeed, '', 'generate and print a new seed phrase'],
'get-address': [c.getAddress, '', 'derive a new address for specified index (0 if not specified)'],
'gen-shielded-address': [c.genShieldedAddress, '', 'generate a new shielded address'],
'get-address': [c.getAddress, '', 'get your native address'],
'gen-shielded-address': [c.genShieldedAddress, '', 'generate a new zkBob shielded address'],
// 'get-private-key': [c.getPrivateKey, ' <password>', 'print the private key'],
'get-balance': [c.getBalance, '', 'fetch and print account balance'],
'get-balance': [c.getBalance, '', 'fetch and print native account balance'],
'get-shielded-balance': [c.getShieldedBalance, '', 'get calculated private balance'],
// 'get-balances': [c.getBalances, '', 'print balances for all'],
'get-token-balance': [c.getTokenBalance, '', ''],
'testnet-mint': [c.mint, ' <amount>', ''],
'transfer': [c.transfer, ' <to> <amount>', 'transfer token, <amount> in base units (e.g.: yoctoNEAR, Wei)'],
'transfer-shielded': [c.transferShielded, '<account> <shielded address> <amount>', ''],
'deposit-shielded': [c.depositShielded, '<account> <amount>', ''],
'withdraw-shielded': [c.withdrawShielded, '<account> <amount>', ''],
'internal-state': [c.getInternalState, '', ''],
'get-token-balance': [c.getTokenBalance, '', 'get token balance (unshielded)'],
'testnet-mint': [c.mint, ' <amount>', 'mint some unshielded tokens'],
'transfer': [c.transfer, ' <to> <amount>', 'transfer unshielded tokens, <amount> in base units (e.g.: yoctoNEAR, Wei)'],
'transfer-shielded': [c.transferShielded, '<shielded address> <amount>', 'move shielded tokens to the another zkBob address (inside a pool)'],
'deposit-shielded': [c.depositShielded, '<amount>', 'shield some tokens'],
'withdraw-shielded': [c.withdrawShielded, '<amount> [address]', 'withdraw shielded tokens to the native address (to the your account if addres is ommited)'],
'internal-state': [c.getInternalState, '', 'print your account and incoming notes'],
'clear': [c.clear, '', 'clear terminal'],
'reset': [c.reset, '', 'reset console state'],
'reset': [c.reset, '', 'log out from the current account'],
'version': [
function () {
this.echo(`zkBob console version ${pjson.version}`);
Expand Down Expand Up @@ -118,8 +118,8 @@ const COMMANDS: { [key: string]: [(...args) => void, string, string] } = {
<div class="comment">// Transfer 1 * 10^18 of deposited tokens the specified address.</div>
<div class="command-example">transfer-shielded "shielded address here" 1000000000000000000</div>
<div class="comment">// Withdraw the remaining 2 * 10^18 from the pool.</div>
<div class="command-example">withdraw-shielded 2000000000000000000</div>
<div class="comment">// If you want to check your shielded balance between '*-shielded' commands:</div>
<div class="command-example">withdraw-shielded 2000000000000000000 [optional_external_address]</div>
<div class="comment">// Check your shielded balance</div>
<div class="command-example">get-shielded-balance</div>
</p>
Expand Down

0 comments on commit be15e06

Please sign in to comment.