Skip to content

Commit

Permalink
feat: invoke raw script
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardojrmcom committed Sep 12, 2022
1 parent 20396d5 commit 318ee14
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ricardojrmcom/use-phantasma-link",
"description": "React hook for PhantasmaLink",
"version": "0.0.2-development",
"version": "0.0.3-development",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"private": false,
Expand Down
43 changes: 43 additions & 0 deletions src/phantasmaLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,49 @@ export class PhantasmaLink {
this.createSocket();
}

invokeRawScript(
chain,
script,
payload,
callback,
platform = 'phantasma',
signature = 'Ed25519',
) {
if (!this.socket) {
callback('not logged in');
return;
}
if (script.length >= 8192) {
console.error('script too big, sorry :(');
return;
}
if (payload == null) {
payload = '';
} else if (typeof payload === 'string') {
let sb = new ScriptBuilder();
let bytes = sb.rawString(payload);
sb.appendBytes(bytes);
payload = sb.script;
} else {
alert('invalid payload, sorry :(');
return;
}

let requestStr = chain + '/' + script;
console.log('teste.' + requestStr);
if (this.version >= 2) {
requestStr = requestStr;
} else {
requestStr = this.nexus + '/' + requestStr;
}

console.log('teste2.' + requestStr);

this.sendLinkRequest('invokeScript/' + requestStr, function (result) {
callback(result);
});
}

invokeScript(script) {
// this.onMessage('Relaying transaction to wallet...')

Expand Down

1 comment on commit 318ee14

@vercel
Copy link

@vercel vercel bot commented on 318ee14 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.