Skip to content

Commit

Permalink
Rebranding to Inplug-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramCrafter committed Oct 2, 2023
1 parent b3c8e26 commit 022dccf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Wallet v5r2
Wallet v5 is custom version of wallet for use instead of v4.
# Wallet Inplug-v1
Wallet Inplug-v1 (previously known as v5) is custom version of wallet for use instead of v4.

There are three main differences from previous versions:
1. execute arbitrary code onchain. User can pass a continuation to be executed -- this is useful for predicting unsafe random.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { keyPairFromSeed, mnemonicToPrivateKey, mnemonicToSeed } from "ton-crypt
import { parseArgs } from "util";
import yargs from "yargs";
import { mnemonic } from "./env";
import { makeSender, WalletContractV5R2 } from "./wallet-v5";
import { makeSender, WalletInplugV1 } from "./wallet-v5";

function expect(a: any) {
return {
Expand All @@ -18,7 +18,7 @@ function expect(a: any) {
const argv = yargs
.option('action', {
alias: 'a',
description: 'The action to perform (info|transfer|<unsupported>install|uninstall|execute)',
description: 'The action to perform (info|transfer|install|<unsupported>uninstall|execute)',
type: 'string',
demandOption: true,
})
Expand All @@ -36,8 +36,9 @@ const argv = yargs
})
.option('body', {
alias: 'b',
description: 'Optional body data',
description: 'Plugin/optional body data',
type: 'string',
demandOption: false,
}).argv;

(async () => {
Expand All @@ -47,25 +48,33 @@ const argv = yargs
const client = new TonClient({ endpoint });

const key = await mnemonicToPrivateKey(mnemonic.split(' '));
const wallet = client.open(WalletContractV5R2.create({workchain: 0, publicKey: key.publicKey}));
const wallet = client.open(WalletInplugV1.create({workchain: 0, publicKey: key.publicKey}));
console.log(wallet.address);
console.log(await wallet.getBalance());
console.log(await wallet.getSeqno());

if (args.action == 'info') {
return;
} else if (args.action == 'transfer') {
const destination = Address.parse(args.dest!!);
const value = toNano(args.value!!);

const body = args.body ? Cell.fromBase64(args.body) : undefined;

console.log(await makeSender(wallet, key.secretKey).send({
to: destination,
value,
body
}));
} else if (args.action == 'install') {
console.warn('Uninstalling plugins is not supported yet.');
const plugin = Cell.fromBase64(args.body!!);
await contract.sendInstallPlugin({secretKey: key.secretKey, code: plugin});
} else if (args.action == 'execute') {
const code = Cell.fromBase64(args.body!!);
await contract.sendExecuteCode({secretKey: key.secretKey, code: code});
} else {
expect(args.action).toBe('uninstall');
console.warn('Uninstalling plugins is not supported yet.');
}

expect(args.action).toBe('transfer');

const destination = Address.parse(args.dest!!);
const value = toNano(args.value!!);

const body = args.body ? Cell.fromBase64(args.body) : undefined;

console.log(await makeSender(wallet, key.secretKey).send({
to: destination,
value,
body
}));
})();
4 changes: 2 additions & 2 deletions test-wallet-v5.ts → test-wallet-inplug-v1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Blockchain } from "@ton-community/sandbox";
import { beginCell, Cell, SendMode, toNano } from "ton-core";
import { randomTestKey } from "ton/dist/utils/randomTestKey";
import { makeSender, WalletContractV5R2 } from "./wallet-v5";
import { makeSender, WalletInplugV1 } from "./wallet-v5";


function expect(a: any) {
Expand All @@ -19,7 +19,7 @@ function expect(a: any) {
const deployer = await blockchain.treasury('deployer');
let key = randomTestKey('v5r1-treasure');

let contract = blockchain.openContract(WalletContractV5R2.create({ workchain: 0, publicKey: key.publicKey }));
let contract = blockchain.openContract(WalletInplugV1.create({ workchain: 0, publicKey: key.publicKey }));
let balance = await contract.getBalance();
expect(contract.address.toString()).toBe('EQBTx-Tt7VSZLXCaQdA007BJDxnqfKRpKL3RFpGdh6Wcxb2J');
expect(balance).toBe(0n);
Expand Down
17 changes: 15 additions & 2 deletions wallet-v5.ts → wallet-inplug-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type InstallPlugin = {action: 'install', code: Cell};
export type InvokeCode = {action: 'invoke', code: Cell};
export type Action = InstallPlugin | InvokeCode | Transfer | UninstallPlugin;

export class WalletContractV5R2 implements Contract {
export class WalletInplugV1 implements Contract {
readonly workchain: number;
readonly publicKey: Buffer;
readonly address: Address;
Expand Down Expand Up @@ -160,6 +160,19 @@ export class WalletContractV5R2 implements Contract {
return this.signMultiAction({seqno, actions, secretKey});
}

async sendExecuteCode(provider: ContractProvider, args: {
seqno?: bigint,
secretKey: Buffer,
code: Cell
}): Promise<void> {
let transfer = this.signMultiAction({
seqno: args.seqno ?? await this._nowrapGetSeqno(provider),
secretKey: args.secretKey,
actions: [{action: 'invoke', code: args.code}]
})
await this.sendExternal(provider, transfer);
}

async sendInstallPlugin(provider: ContractProvider, args: {
seqno?: bigint,
secretKey: Buffer,
Expand Down Expand Up @@ -203,7 +216,7 @@ export class WalletContractV5R2 implements Contract {
}
}

export function makeSender(contract: SandboxContract<WalletContractV5R2>, secretKey: Buffer) : Sender {
export function makeSender(contract: SandboxContract<WalletInplugV1>, secretKey: Buffer) : Sender {
return {
send: async (args: SenderArguments) => {
let seqno = await contract.getSeqno();
Expand Down

0 comments on commit 022dccf

Please sign in to comment.