From 62b934ff52d5684e9edd9cba2de4e2c910c4d77b Mon Sep 17 00:00:00 2001 From: Igor Sikachyna Date: Mon, 22 Jul 2024 07:40:46 -0400 Subject: [PATCH] BLOCK-2445 - Updated steps for transaction signing and naming of Contract Name (#26) --- CHANGELOG.md | 5 ++ README.md | 26 ++++++++- package.json | 2 +- src/commands/apiFlows/getCurrencyBalance.ts | 2 +- src/commands/apiFlows/getTable.ts | 4 +- src/commands/transact.ts | 65 +++++++++++++++------ src/service/api.ts | 8 +-- 7 files changed, 84 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edffdc..631252e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the "ultra-cpp" extension will be documented in this file. +## 1.4.2 + +- Renamed 'Contract Name' to 'Contract Account Name' to reduce the confusion +- Updated transaction creation flow to remove the extra API selection step + ## 1.4.1 - Added Wharfkit support diff --git a/README.md b/README.md index c137764..0158389 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ These can be accessed with `(CTRL / CMD) + SHIFT + P` or through the Command Pal ### Wallet Service -The wallet service allows you to store private keys inside of VSCode's global state with encryption. However, `1.2.2` of this extension is still missing signing transactions, and such. Will add soon. +The wallet service allows you to store private keys inside of VSCode's global state with encryption. - Ultra: Wallet - Create - Creates a wallet with 'aes-256-cbc' encryption @@ -93,4 +93,26 @@ The wallet service allows you to store private keys inside of VSCode's global st
- Q. How do I select which contract to compile in a monorepo? - - A. Open the root `.cpp` file of the smart contract in VSCode, and have it as the active file. \ No newline at end of file + - A. Open the root `.cpp` file of the smart contract in VSCode, and have it as the active file. + +## How to build and install locally + +Install the VSCode tool for local packaging + +```sh +npm install -g vsce +``` + +Install dependencies within the directory of this repository + +```sh +npm install +``` + +Use the following command each time you made some changes and want to apply them and install the extension + +```sh +rm -rf ./ultra-cpp-*.vsix && vsce package && code --install-extension ultra-cpp-*.vsix +``` + +You will also need to restart the VSCode window to reload the extension after executing the above command. Otherwise the source code changes will not be reflected. To do this, use `Ctrl + Shift + P` to open command palette and type `>Reload Window`. diff --git a/package.json b/package.json index c52b5b7..49dc716 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "repository": { "url": "https://github.com/ultraio/ultra-cpp-extension" }, - "version": "1.4.1", + "version": "1.4.2", "engines": { "vscode": "^1.70.0" }, diff --git a/src/commands/apiFlows/getCurrencyBalance.ts b/src/commands/apiFlows/getCurrencyBalance.ts index 2d7dbc1..264f59f 100644 --- a/src/commands/apiFlows/getCurrencyBalance.ts +++ b/src/commands/apiFlows/getCurrencyBalance.ts @@ -16,7 +16,7 @@ const multiQuery = [ { property: 'code', inputOptions: { - title: 'Contract Name', + title: 'Contract Account Name', value: 'eosio.token', placeHolder: 'Name of the contract', }, diff --git a/src/commands/apiFlows/getTable.ts b/src/commands/apiFlows/getTable.ts index 6fd239a..22afc42 100644 --- a/src/commands/apiFlows/getTable.ts +++ b/src/commands/apiFlows/getTable.ts @@ -8,9 +8,9 @@ const multiQuery = [ { property: 'code', inputOptions: { - title: 'Contract Name', + title: 'Contract Account Name', value: '', - placeHolder: 'Name of the contract the table belongs to', + placeHolder: 'Name of the contract account the table belongs to', }, }, { diff --git a/src/commands/transact.ts b/src/commands/transact.ts index 688f011..e4f1d78 100644 --- a/src/commands/transact.ts +++ b/src/commands/transact.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import * as Service from '../service/index'; import * as Utility from '../utility/index'; +import { API } from '@ultraos/ultra-signer-lib'; async function register() { const disposable = vscode.commands.registerCommand(Service.command.commandNames.transact, async () => { @@ -9,14 +10,22 @@ async function register() { return; } - const api = await Service.api.getSignable(); + const endpoint = await Service.api.pick(); + if (!endpoint) { + return; + } + + const api = await Service.api.getSignable(endpoint).catch((err) => { + console.log(err); + return undefined; + }); if (!api) { vscode.window.showErrorMessage('Could not create signable API. Wrong password? Bad endpoint?'); return; } const contract = await Utility.quickInput.create({ - title: 'Contract Name', + title: 'Contract Account Name', placeHolder: 'eosio.token', value: '', }); @@ -25,7 +34,7 @@ async function register() { return; } - const ultraApi = await Service.api.getUltraApi().catch((err) => { + const ultraApi = await Service.api.getUltraApi(endpoint).catch((err) => { console.log(err); return undefined; }); @@ -40,8 +49,8 @@ async function register() { return undefined; }); - if (!result || !result.abi) { - vscode.window.showErrorMessage(`Contract '${contract}' does not have a contract set`); + if (!result || !result.abi) { + vscode.window.showErrorMessage(`Account '${contract}' does not have a contract set`); return; } @@ -76,15 +85,40 @@ async function register() { return; } - // Ask for Signer - const signer = await Utility.quickInput.create({ - title: 'Who is signing?', - placeHolder: 'myacc@active', - value: '', - }); + let actor: string = '', permission: string = ''; - if (!signer) { - return; + while (actor.length <= 0) { + // Ask for Signer + const signer = await Utility.quickInput.create({ + title: 'Who is signing?', + placeHolder: 'myacc@active', + value: '', + }); + + if (!signer) { + return; + } + + [actor, permission] = signer.split('@'); + + if (!permission) { + permission = 'active'; + } + + try { + // Ensure this account can be signed as + const testTrx = await api.buildTransaction([{ + account: 'eosio.token', + name: 'transfer', + authorization: [{ actor, permission }], + data: {from: actor, to: actor, quantity: '0.00000000 UOS', memo: ''} + }]); + const signature = await api.signTransaction(testTrx); + } catch (err) { + console.log(err); + vscode.window.showErrorMessage(`Was not able to sign as ${signer}.`); + actor = ''; + } } let formData: any; @@ -99,11 +133,6 @@ async function register() { return; } - let [actor, permission] = signer.split('@'); - if (!permission) { - permission = 'active'; - } - const outputChannel = Utility.outputChannel.get(); const transactionResult = await api .transact( diff --git a/src/service/api.ts b/src/service/api.ts index 5e6de17..97f0f52 100644 --- a/src/service/api.ts +++ b/src/service/api.ts @@ -71,8 +71,8 @@ export async function pick(): Promise { return api; } -export async function getUltraApi(): Promise { - const endpoint = await pick(); +export async function getUltraApi(customEndpoint?: string): Promise { + const endpoint = customEndpoint ? customEndpoint : await pick(); if (!endpoint) { return undefined; } @@ -80,8 +80,8 @@ export async function getUltraApi(): Promise { return connect(endpoint); } -export async function getSignable(): Promise { - const endpoint = await pick(); +export async function getSignable(customEndpoint?: string): Promise { + const endpoint = customEndpoint ? customEndpoint : await pick(); if (!endpoint) { return undefined; }