Skip to content

Commit

Permalink
BLOCK-2445 - Updated steps for transaction signing and naming of Cont…
Browse files Browse the repository at this point in the history
…ract Name (#26)
  • Loading branch information
igor-sikachyna authored Jul 22, 2024
1 parent fea9e92 commit 62b934f
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,4 +93,26 @@ The wallet service allows you to store private keys inside of VSCode's global st
<br />

- 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.
- 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`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apiFlows/getCurrencyBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const multiQuery = [
{
property: 'code',
inputOptions: {
title: 'Contract Name',
title: 'Contract Account Name',
value: 'eosio.token',
placeHolder: 'Name of the contract',
},
Expand Down
4 changes: 2 additions & 2 deletions src/commands/apiFlows/getTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
{
Expand Down
65 changes: 47 additions & 18 deletions src/commands/transact.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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: '',
});
Expand All @@ -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;
});
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ export async function pick(): Promise<string | undefined> {
return api;
}

export async function getUltraApi(): Promise<UltraAPI | undefined> {
const endpoint = await pick();
export async function getUltraApi(customEndpoint?: string): Promise<UltraAPI | undefined> {
const endpoint = customEndpoint ? customEndpoint : await pick();
if (!endpoint) {
return undefined;
}

return connect(endpoint);
}

export async function getSignable(): Promise<API | undefined> {
const endpoint = await pick();
export async function getSignable(customEndpoint?: string): Promise<API | undefined> {
const endpoint = customEndpoint ? customEndpoint : await pick();
if (!endpoint) {
return undefined;
}
Expand Down

0 comments on commit 62b934f

Please sign in to comment.