feat: Add initial atomic swap
This commit is contained in:
parent
36612e791d
commit
47939cac3d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
data
|
@ -8,3 +8,8 @@ Import this URL:
|
|||||||
```
|
```
|
||||||
https://git.woodburn.au/nathanwoodburn/firesales-plugin.git
|
https://git.woodburn.au/nathanwoodburn/firesales-plugin.git
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
npm install shakedex
|
||||||
|
npm install hsd
|
||||||
|
node node_modules/shakedex/bin/shakedex transfer-lock coolcode -n main -w hot -a y5cSK42tgVCdt4E58jkHjI3nQ9GU32bC -p ./data
|
46
firesales.py
46
firesales.py
@ -1,6 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
import account
|
import account
|
||||||
import requests
|
import requests
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
path = os.path.realpath("customPlugins/firesales-plugin")
|
||||||
|
|
||||||
# Plugin Data
|
# Plugin Data
|
||||||
info = {
|
info = {
|
||||||
@ -12,6 +16,18 @@ info = {
|
|||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
functions = {
|
functions = {
|
||||||
|
"init": {
|
||||||
|
"name": "Init",
|
||||||
|
"description": "Install prerequisites for atomic swaps",
|
||||||
|
"type":"default",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"status": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Status"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"list": {
|
"list": {
|
||||||
"name": "List",
|
"name": "List",
|
||||||
"description": "List a new domain",
|
"description": "List a new domain",
|
||||||
@ -60,6 +76,36 @@ functions = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def init(params, authentication):
|
||||||
|
# Install npm packages
|
||||||
|
if not os.path.exists(f'{path}/node_modules'):
|
||||||
|
try:
|
||||||
|
result = subprocess.run(["npm", "install", ], capture_output=True, text=True, cwd=path)
|
||||||
|
if result.returncode != 0:
|
||||||
|
return {"status": "Error: " + result.stderr}
|
||||||
|
except:
|
||||||
|
return {"status": "Error: Failed to install npm packages"}
|
||||||
|
|
||||||
|
# Install js patch files
|
||||||
|
# Copy shakedex/main.js to node_modules/shakedex/src/cli/main.js
|
||||||
|
try:
|
||||||
|
result = subprocess.run(["cp", f'{path}/shakedex/main.js', f'{path}/node_modules/shakedex/src/cli/main.js'], capture_output=True, text=True, cwd=path)
|
||||||
|
if result.returncode != 0:
|
||||||
|
return {"status": "Error: " + result.stderr}
|
||||||
|
except:
|
||||||
|
return {"status": "Error: Failed to install js patch files"}
|
||||||
|
|
||||||
|
# Copy shakedex/index.js to node_modules/shakedex/src/index.js
|
||||||
|
try:
|
||||||
|
result = subprocess.run(["cp", f'{path}/shakedex/context.js', f'{path}/node_modules/shakedex/src/context.js'], capture_output=True, text=True, cwd=path)
|
||||||
|
if result.returncode != 0:
|
||||||
|
return {"status": "Error: " + result.stderr}
|
||||||
|
except:
|
||||||
|
return {"status": "Error: Failed to install js patch files"}
|
||||||
|
|
||||||
|
return {"status": "Success"}
|
||||||
|
|
||||||
|
|
||||||
def list(params, authentication):
|
def list(params, authentication):
|
||||||
domain = params["domain"]
|
domain = params["domain"]
|
||||||
price = params["price"]
|
price = params["price"]
|
||||||
|
1602
package-lock.json
generated
Normal file
1602
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
package.json
Normal file
19
package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "firesales-plugin",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "FireSales Plugin",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.woodburn.au/nathanwoodburn/firesales-plugin.git"
|
||||||
|
},
|
||||||
|
"author": "Nathan.Woodburn/",
|
||||||
|
"license": "AGPL-3.0-only",
|
||||||
|
"dependencies": {
|
||||||
|
"hsd": "^7.0.1",
|
||||||
|
"shakedex": "^0.0.19"
|
||||||
|
}
|
||||||
|
}
|
77
shakedex/context.js
Normal file
77
shakedex/context.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
const { NodeClient, WalletClient } = require('hsd/lib/client');
|
||||||
|
const Network = require('hsd/lib/protocol/network.js');
|
||||||
|
const passwordPrompt = require('password-prompt');
|
||||||
|
|
||||||
|
class Context {
|
||||||
|
constructor(
|
||||||
|
networkName,
|
||||||
|
walletId,
|
||||||
|
apiKey,
|
||||||
|
passphraseGetter = noopPassphraseGetter,
|
||||||
|
host = '127.0.0.1',
|
||||||
|
nodeApiKey,
|
||||||
|
) {
|
||||||
|
this.networkName = networkName;
|
||||||
|
this.network = Network.get(networkName);
|
||||||
|
this.walletId = walletId;
|
||||||
|
this.nodeClient = new NodeClient({
|
||||||
|
port: this.network.rpcPort,
|
||||||
|
host,
|
||||||
|
apiKey: nodeApiKey || apiKey,
|
||||||
|
});
|
||||||
|
this.walletClient = new WalletClient({
|
||||||
|
port: this.network.walletPort,
|
||||||
|
host,
|
||||||
|
apiKey: apiKey,
|
||||||
|
});
|
||||||
|
this.wallet = this.walletClient.wallet(walletId);
|
||||||
|
this.passphraseGetter = passphraseGetter;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPassphrase = () => {
|
||||||
|
return this.passphraseGetter();
|
||||||
|
};
|
||||||
|
|
||||||
|
execNode = (method, ...args) => {
|
||||||
|
return this.nodeClient.execute(method, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
execWallet = async (method, ...args) => {
|
||||||
|
await this.walletClient.execute('selectwallet', [this.walletId]);
|
||||||
|
return this.walletClient.execute(method, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
unlockWallet = async () => {
|
||||||
|
const pass = await this.getPassphrase();
|
||||||
|
if (pass === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.wallet.unlock(pass, 60);
|
||||||
|
};
|
||||||
|
|
||||||
|
getMTP = async () => {
|
||||||
|
const info = await this.execNode('getblockchaininfo');
|
||||||
|
return info.mediantime;
|
||||||
|
};
|
||||||
|
|
||||||
|
getHeight = async () => {
|
||||||
|
const info = await this.execNode('getblockchaininfo');
|
||||||
|
return info.blocks;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Context = Context;
|
||||||
|
|
||||||
|
exports.staticPassphraseGetter = function (passphrase) {
|
||||||
|
return () => new Promise((resolve) => resolve(passphrase));
|
||||||
|
};
|
||||||
|
|
||||||
|
function noopPassphraseGetter() {
|
||||||
|
return new Promise((resolve) => resolve(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.promptPassphraseGetter = function (
|
||||||
|
prefix = '>> Please enter your passphrase: '
|
||||||
|
) {
|
||||||
|
return () => new Promise((resolve) => resolve(passwordPrompt(prefix)));
|
||||||
|
};
|
1058
shakedex/main.js
Normal file
1058
shakedex/main.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user