Skip to content

Commit eb1a7c4

Browse files
committed
added transfer & whoami cli methods
1 parent 27b989b commit eb1a7c4

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Depending on your use-cases, we have several optional dependencies:
4444
- You can use [hollowdb-prover](https://www.npmjs.com/package/hollowdb-prover) as a simple utility that generates zero-knowledge proofs that are verifiable by HollowDB.
4545
- You can use LMDB cache within your Warp instance via [warp-contracts-lmdb](https://www.npmjs.com/package/warp-contracts-lmdb).
4646
- You can use Redis cache within your warp instance via [warp-contracts-redis](https://www.npmjs.com/package/warp-contracts-redis) together with [ioredis](https://www.npmjs.com/package/ioredis).
47+
- When you are evaluating a contract that uses ZK proofs, you should also use [warp-contracts-plugin-snarkjs](https://www.npmjs.com/package/warp-contracts-plugin-snarkjs) and [warp-contracts-plugin-ethers](https://www.npmjs.com/package/warp-contracts-plugin-ethers).
4748

4849
## Usage
4950

src/bin/cli.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {transfer} from './transfer';
1313
const BASE_CONTRACT_NAME = 'hollowdb';
1414

1515
yargs(hideBin(process.argv))
16-
.scriptName('yarn contract')
16+
.scriptName('pnpm contract')
1717
// .example('$0 build -n my-contract', 'Build your contract')
1818
// .example('$0 deploy -n my-contract -w ./my/wallet.json', 'Deploy to mainnet')
1919
// .example('$0 evolve -n new-contract -c txId -w ./my/wallet.json', 'Evolve an existing contract with new source')
@@ -46,6 +46,26 @@ yargs(hideBin(process.argv))
4646
})
4747
.string(['wallet', 'name', 'init', 'target', 'sourceTxId', 'contractTxId'])
4848

49+
.command(
50+
'whoami',
51+
'Display information about your wallet',
52+
yargs => yargs.demandOption(['wallet']),
53+
async args => {
54+
const warp = prepareWarp(args.target);
55+
const wallet = prepareWallet(args.wallet);
56+
57+
const address = await warp.arweave.wallets.getAddress(wallet);
58+
const balance = await warp.arweave.wallets.getBalance(address);
59+
const lastTxId = await warp.arweave.wallets.getLastTransactionID(address);
60+
61+
console.table({
62+
address,
63+
balance: parseFloat(balance),
64+
lastTxId: lastTxId === '' ? 'no transactions yet' : lastTxId,
65+
});
66+
}
67+
)
68+
4969
.command(
5070
'deploy',
5171
'Deploy a new contract',

src/bin/transfer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {lastPossibleSortKey} from 'warp-contracts';
1+
import {LoggerFactory, lastPossibleSortKey} from 'warp-contracts';
22
import type {JWKInterface, Warp} from 'warp-contracts';
33
import {SDK} from '../hollowdb';
44

@@ -10,9 +10,7 @@ async function loadState(sdk: SDK) {
1010
}, 2000);
1111

1212
await sdk.getState();
13-
1413
clearInterval(interval);
15-
console.log('Done!\n');
1614
}
1715

1816
// gets keys directly from the storage layer (no interactions)
@@ -35,23 +33,25 @@ export async function transfer(
3533
srcContractTxId: string,
3634
destContractTxId: string
3735
): Promise<number> {
38-
console.log('Creating source SDK...');
36+
LoggerFactory.INST.logLevel('none');
37+
38+
console.time('Creating source SDK');
3939
const src = new SDK(wallet, srcContractTxId, warp);
4040
await loadState(src);
41+
console.timeEnd('Creating source SDK');
42+
console.log('https://sonar.warp.cc/?#/app/contract/' + srcContractTxId);
4143

42-
console.log('Creating destination SDK...');
44+
console.time('\nCreating destination SDK');
4345
const dest = new SDK(wallet, destContractTxId, warp);
4446
await loadState(dest);
45-
46-
console.log('Source : https://sonar.warp.cc/?#/app/contract/' + srcContractTxId);
47-
console.log('Destination: https://sonar.warp.cc/?#/app/contract/' + destContractTxId);
48-
console.log('');
47+
console.timeEnd('\nCreating destination SDK');
48+
console.log('https://sonar.warp.cc/?#/app/contract/' + destContractTxId);
4949

5050
const [srcKeys, destKeys] = await Promise.all([
5151
getKeysFromStorage(src, srcContractTxId),
5252
getKeysFromStorage(dest, destContractTxId),
5353
]);
54-
console.log('Number of keys:', '\n\tSRC:', srcKeys.length, '\n\tDEST:', destKeys.length);
54+
console.log('\nNumber of keys:', '\n Source:', srcKeys.length, '\n Destination:', destKeys.length);
5555

5656
let numKeys = 0;
5757
async function transferKey(i: number) {

src/contracts/README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ To begin, clone the repo and install the packages:
99
git clone https://github.com/firstbatchxyz/hollowdb
1010

1111
# install packages
12-
yarn
12+
pnpm install
1313
```
1414

15-
Our command-line tool can be called via `yarn contract`. You will see the message below if you type `yarn contract --help`:
15+
Our command-line tool can be called via `pnpm contract`. You will see the message below if you type `pnpm contract --help`:
1616

1717
```sh
18-
yarn contract <command>
18+
pnpm contract <command>
1919

2020
Commands:
21-
yarn contract deploy Deploy a new contract
22-
yarn contract evolve Evolve an existing contract
23-
yarn contract create Create your own custom contract
24-
yarn contract build Build a contract
21+
pnpm contract whoami Display information about your wallet
22+
pnpm contract deploy Deploy a new contract
23+
pnpm contract evolve Evolve an existing contract
24+
pnpm contract create Create your own custom contract
25+
pnpm contract build Build a contract
26+
pnpm contract transfer Transfer keys & values from one contract to another
2527

2628
Options:
2729
--help Show help [boolean]
@@ -41,25 +43,25 @@ As shown in the help message above, building, deploying, or evolving a contract
4143

4244
```sh
4345
# build all contracts
44-
yarn contract build
46+
pnpm contract build
4547

4648
# build a specific contract
47-
yarn contract build -n contract-name
49+
pnpm contract build -n contract-name
4850

4951
# deploy to mainnet from a local source code
50-
yarn contract deploy -w ./secret/wallet.json -n contract-name
52+
pnpm contract deploy -w ./secret/wallet.json -n contract-name
5153

5254
# deploy to mainnet from an existing contract source
53-
yarn contract deploy -w ./secret/wallet.json -s sourceTxId
55+
pnpm contract deploy -w ./secret/wallet.json -s sourceTxId
5456

5557
# deploy to testnet from a local source code with a specific state
56-
yarn contract deploy -w ./secret/wallet.json -n contract-name -t test -i ./path/to/state.json
58+
pnpm contract deploy -w ./secret/wallet.json -n contract-name -t test -i ./path/to/state.json
5759

5860
# evolve a contract on mainnet to a local source code
59-
yarn contract evolve -w ./secret/wallet.json -c contractTxId -n contract-name
61+
pnpm contract evolve -w ./secret/wallet.json -c contractTxId -n contract-name
6062

6163
# evolve a contract on mainnet to an existing contract source
62-
yarn contract evolve -w ./secret/wallet.json -c contractTxId -s sourceTxId
64+
pnpm contract evolve -w ./secret/wallet.json -c contractTxId -s sourceTxId
6365
```
6466

6567
Thanks to the file structure we are using here, you do not need to worry about paths to your contracts or their initial states. When you provide a contract name with `-n` option, the CLI knows to look for the contract source code at `./src/contracts/<name>.contract.ts` and such.
@@ -71,7 +73,7 @@ A SmartWeave contract for Warp Contracts is basically a single JS file that expo
7173
To begin creating your own contract, simply do:
7274

7375
```sh
74-
yarn contract create -n your-new-contract
76+
pnpm contract create -n your-new-contract
7577
```
7678

7779
Within your newly created contract, you can modify the existing functions or add your own.
@@ -235,4 +237,4 @@ Within this directory:
235237
- `states` has the initial state for each contract.
236238
- `types` has types, as usual in TypeScript.
237239
- `utils` has common utility functions, such as proof verification.
238-
- the remaining files with `.contract.ts` extension are the smart-contracts, and when you run `yarn contract:build` they will be detected and built.
240+
- the remaining files with `.contract.ts` extension are the smart-contracts, and when you run `pnpm contract build` they will be detected and built.

0 commit comments

Comments
 (0)