Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
cdf73cae84 | |||
2bb1fbc3a5 | |||
52d9d45106 | |||
cd362f805b | |||
ba7a73d1a9 | |||
c00603c020 | |||
47939cac3d |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
data
|
@ -7,4 +7,9 @@ Go to Plugins > Custom Plugin Manager
|
|||||||
Import this URL:
|
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
|
202
firesales.py
202
firesales.py
@ -1,6 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
import account
|
import account
|
||||||
import requests
|
import requests
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
path = os.path.realpath("customPlugins/firesales-plugin")
|
||||||
|
userData = os.path.realpath(f"user_data/firesales/{account.HSD_NETWORK}")
|
||||||
|
|
||||||
# Plugin Data
|
# Plugin Data
|
||||||
info = {
|
info = {
|
||||||
@ -12,6 +17,81 @@ info = {
|
|||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
functions = {
|
functions = {
|
||||||
|
"init": {
|
||||||
|
"name": "Init",
|
||||||
|
"description": "Install prerequisites for atomic swaps",
|
||||||
|
"type":"default",
|
||||||
|
"params": {},
|
||||||
|
"returns": {
|
||||||
|
"status": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Status"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"startListingTransfer": {
|
||||||
|
"name": "Start Listing Transfer",
|
||||||
|
"description": "Start listing transfer. You will need to wait 2 days to send the finalize before listing",
|
||||||
|
"type":"default",
|
||||||
|
"params": {
|
||||||
|
"domain": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Domain to list"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"status": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Status"
|
||||||
|
},
|
||||||
|
"txid": {
|
||||||
|
"type": "tx",
|
||||||
|
"name": "Transaction ID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"finalizeListingTransfer": {
|
||||||
|
"name": "Finalize Listing Transfer",
|
||||||
|
"description": "Finalize listing transfer",
|
||||||
|
"type":"default",
|
||||||
|
"params": {
|
||||||
|
"domain": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Domain to list"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"status": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Status"
|
||||||
|
},
|
||||||
|
"txid": {
|
||||||
|
"type": "tx",
|
||||||
|
"name": "Transaction ID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"createListing": {
|
||||||
|
"name": "CreateListing",
|
||||||
|
"description": "CreateListing a new domain",
|
||||||
|
"type":"default",
|
||||||
|
"params": {
|
||||||
|
"domain": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Domain to list"
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"type": "number",
|
||||||
|
"name": "Price of the domain"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"status": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Status of the listing"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"list": {
|
"list": {
|
||||||
"name": "List",
|
"name": "List",
|
||||||
"description": "List a new domain",
|
"description": "List a new domain",
|
||||||
@ -60,6 +140,128 @@ 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 startListingTransfer(params, authentication):
|
||||||
|
domain = params["domain"]
|
||||||
|
# Generate command
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
passphrase = authentication.split(":")[1]
|
||||||
|
api_key = os.getenv("hsd_api")
|
||||||
|
host = os.getenv("hsd_ip")
|
||||||
|
if host is None:
|
||||||
|
host = "127.0.0.1"
|
||||||
|
|
||||||
|
# node node_modules/shakedex/bin/shakedex transfer-lock domain -n main -w wallet -a key -p ./data --httphost host
|
||||||
|
process = subprocess.Popen(
|
||||||
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "transfer-lock", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
# Wait for the process to finish
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
print(f"STDOUT: {stdout}")
|
||||||
|
|
||||||
|
if stderr is None:
|
||||||
|
stderr = stdout
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
return {"status": f"Error: {stderr}", "txid": None}
|
||||||
|
|
||||||
|
txhash:str = stdout.split(" hash ")[1]
|
||||||
|
txhash = txhash.split("\n")[0].rstrip('.')
|
||||||
|
return {"status": "Success", "txid": txhash}
|
||||||
|
|
||||||
|
def finalizeListingTransfer(params, authentication):
|
||||||
|
domain = params["domain"]
|
||||||
|
# Generate command
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
passphrase = authentication.split(":")[1]
|
||||||
|
api_key = os.getenv("hsd_api")
|
||||||
|
host = os.getenv("hsd_ip")
|
||||||
|
if host is None:
|
||||||
|
host = "127.0.0.1"
|
||||||
|
|
||||||
|
process = subprocess.Popen(
|
||||||
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "finalize-lock", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
# Wait for the process to finish
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
print(f"STDOUT: {stdout}")
|
||||||
|
|
||||||
|
if stderr is None:
|
||||||
|
stderr = stdout
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
return {"status": f"Error: {stderr}", "txid": None}
|
||||||
|
|
||||||
|
txhash:str = stdout.split(" hash ")[1]
|
||||||
|
txhash = txhash.split("\n")[0].rstrip('.')
|
||||||
|
return {"status": "Success", "txid": txhash}
|
||||||
|
|
||||||
|
def createListing(params, authentication):
|
||||||
|
domain = params["domain"]
|
||||||
|
price = params["price"]
|
||||||
|
# Generate command
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
passphrase = authentication.split(":")[1]
|
||||||
|
api_key = os.getenv("hsd_api")
|
||||||
|
host = os.getenv("hsd_ip")
|
||||||
|
if host is None:
|
||||||
|
host = "127.0.0.1"
|
||||||
|
|
||||||
|
process = subprocess.Popen(
|
||||||
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "create-auction", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
# Wait for the process to finish
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
print(f"STDOUT: {stdout}")
|
||||||
|
|
||||||
|
if stderr is None:
|
||||||
|
stderr = stdout
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
return {"status": f"Error: {stderr}", "txid": None}
|
||||||
|
|
||||||
|
txhash:str = stdout.split(" hash ")[1]
|
||||||
|
txhash = txhash.split("\n")[0].rstrip('.')
|
||||||
|
return {"status": "Success", "txid": txhash}
|
||||||
|
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
67
shakedex/context.js
Normal file
67
shakedex/context.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const { NodeClient, WalletClient } = require('hsd/lib/client');
|
||||||
|
const Network = require('hsd/lib/protocol/network.js');
|
||||||
|
const readline = require("readline");
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
1045
shakedex/main.js
Normal file
1045
shakedex/main.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user