Compare commits

...
9 Commits
Author SHA1 Message Date
Chris Troutner 0b1d3e63f6 Merge pull request #64 from Permissionless-Software-Foundation/ct-unstable
feat(order): Adding functions needed by AMM
2022-12-02 20:07:54 -08:00
Chris Troutner 549fd4fd5a feat(order): Adding functions needed by AMM 2022-12-02 07:44:35 -08:00
Chris Troutner 846ee21c48 Merge pull request #63 from Permissionless-Software-Foundation/ct-unstable
feat(Orders): Added new REST endpoint to get all Orders
2022-12-01 15:12:46 -08:00
Chris Troutner 6654836440 Merge branch 'master' into ct-unstable 2022-12-01 15:10:41 -08:00
Chris Troutner a25a13673e feat(Orders): Added new REST endpoint to get all Orders 2022-12-01 15:10:04 -08:00
Chris Troutner 30eed1ffb1 Merge pull request #62 from Permissionless-Software-Foundation/ct-unstable
fix(production): Updating docker images
2022-11-29 15:49:36 -08:00
Chris Troutner 7884cffdc6 fix(production): Updating docker images 2022-11-29 15:47:18 -08:00
Chris Troutner c1a8210fa7 Merge pull request #61 from Permissionless-Software-Foundation/ct-unstable
fix(p2wdb-esm): Bumping to v2.2.8
2022-11-03 05:58:54 -07:00
Chris Troutner 9f3b482f57 fix(p2wdb-esm): Bumping to v2.2.8 2022-11-03 05:56:48 -07:00
8 changed files with 153 additions and 26 deletions
+2 -1
View File
@@ -46,7 +46,8 @@ export default {
// : 'https://wa-usa-bch-consumer.fullstackcash.nl',
// P2WDB URL that will accept API calls from the p2wdb npm library.
p2wdbUrl: process.env.P2WDB_URL ? process.env.P2WDB_URL : 'https://p2wdb.fullstack.cash',
// p2wdbUrl: process.env.P2WDB_URL ? process.env.P2WDB_URL : 'https://p2wdb.fullstack.cash',
p2wdbUrl: process.env.P2WDB_URL ? process.env.P2WDB_URL : 'http://localhost:5010',
// FullStack.cash account information, used for automatic JWT handling.
getJwtAtStartup: process.env.GET_JWT_AT_STARTUP ? true : false,
+19 -14
View File
@@ -13,6 +13,7 @@
"@psf/bch-js": "6.5.1",
"axios": "0.27.2",
"bch-message-lib": "2.2.1",
"bch-token-sweep": "2.2.1",
"bcryptjs": "2.4.3",
"bitcoincashjs-lib": "3.3.3",
"glob": "7.1.6",
@@ -38,7 +39,7 @@
"mongoose": "5.13.14",
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
"nodemailer": "6.7.5",
"p2wdb-esm": "2.2.7",
"p2wdb-esm": "2.2.8",
"passport-local": "1.0.0",
"public-ip": "4.0.4",
"winston": "3.3.3",
@@ -46,7 +47,6 @@
},
"devDependencies": {
"apidoc": "0.51.1",
"bch-token-sweep": "2.1.2",
"c8": "7.12.0",
"chai": "4.3.0",
"coveralls": "2.11.4",
@@ -2263,9 +2263,9 @@
}
},
"node_modules/bch-token-sweep": {
"version": "2.1.2",
"dev": true,
"license": "MIT",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/bch-token-sweep/-/bch-token-sweep-2.2.1.tgz",
"integrity": "sha512-f4UGEpPXzea7HQMRSEb6h/amXiwrlsMBAjl1dVYg5//26IDWeG+e3qVNtMJhm00NMZ0BS+LasUa2xlz0UVziZA==",
"dependencies": {
"bch-donation": "1.1.2",
"bignumber.js": "9.0.0"
@@ -8853,6 +8853,8 @@
"node_modules/node-fetch": {
"name": "@achingbrain/node-fetch",
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==",
"license": "MIT",
"engines": {
"node": "4.x || >=6.0.0"
@@ -11865,9 +11867,9 @@
}
},
"node_modules/p2wdb-esm": {
"version": "2.2.7",
"resolved": "https://registry.npmjs.org/p2wdb-esm/-/p2wdb-esm-2.2.7.tgz",
"integrity": "sha512-528nGjthkkAf8n4H7jSX52pCpsprKgRfZKB4emIYHkOFo9rHYOOZMLlbRkluYtAThjVxJd7w3fyplZFPEXzlyA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/p2wdb-esm/-/p2wdb-esm-2.2.8.tgz",
"integrity": "sha512-wqTj6HaUdSMDFjp9a2lAGUembGtLxDxBH+PNUNnCHG1RSrLsrFrYFzMc48RlW9BGWybqypstrhORHrlZ30aygA==",
"dependencies": {
"@chris.troutner/retry-queue-commonjs": "1.0.8",
"axios": "0.24.0"
@@ -17228,8 +17230,9 @@
"requires": {}
},
"bch-token-sweep": {
"version": "2.1.2",
"dev": true,
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/bch-token-sweep/-/bch-token-sweep-2.2.1.tgz",
"integrity": "sha512-f4UGEpPXzea7HQMRSEb6h/amXiwrlsMBAjl1dVYg5//26IDWeG+e3qVNtMJhm00NMZ0BS+LasUa2xlz0UVziZA==",
"requires": {
"bch-donation": "1.1.2",
"bignumber.js": "9.0.0"
@@ -21599,7 +21602,9 @@
}
},
"node-fetch": {
"version": "npm:@achingbrain/node-fetch@2.6.7"
"version": "npm:@achingbrain/node-fetch@2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g=="
},
"node-forge": {
"version": "1.3.1"
@@ -23626,9 +23631,9 @@
"dev": true
},
"p2wdb-esm": {
"version": "2.2.7",
"resolved": "https://registry.npmjs.org/p2wdb-esm/-/p2wdb-esm-2.2.7.tgz",
"integrity": "sha512-528nGjthkkAf8n4H7jSX52pCpsprKgRfZKB4emIYHkOFo9rHYOOZMLlbRkluYtAThjVxJd7w3fyplZFPEXzlyA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/p2wdb-esm/-/p2wdb-esm-2.2.8.tgz",
"integrity": "sha512-wqTj6HaUdSMDFjp9a2lAGUembGtLxDxBH+PNUNnCHG1RSrLsrFrYFzMc48RlW9BGWybqypstrhORHrlZ30aygA==",
"requires": {
"@chris.troutner/retry-queue-commonjs": "1.0.8",
"axios": "0.24.0"
+2 -2
View File
@@ -32,6 +32,7 @@
"@psf/bch-js": "6.5.1",
"axios": "0.27.2",
"bch-message-lib": "2.2.1",
"bch-token-sweep": "2.2.1",
"bcryptjs": "2.4.3",
"bitcoincashjs-lib": "3.3.3",
"glob": "7.1.6",
@@ -57,7 +58,7 @@
"mongoose": "5.13.14",
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
"nodemailer": "6.7.5",
"p2wdb-esm": "2.2.7",
"p2wdb-esm": "2.2.8",
"passport-local": "1.0.0",
"public-ip": "4.0.4",
"winston": "3.3.3",
@@ -65,7 +66,6 @@
},
"devDependencies": {
"apidoc": "0.51.1",
"bch-token-sweep": "2.1.2",
"c8": "7.12.0",
"chai": "4.3.0",
"coveralls": "2.11.4",
+8 -8
View File
@@ -70,10 +70,10 @@ services:
restart: always
bch-dex:
build:
context: ./bch-dex/
dockerfile: Dockerfile
#image: christroutner/bch-dex:v2.0.8
#build:
# context: ./bch-dex/
# dockerfile: Dockerfile
image: christroutner/bch-dex:v2.0.12
container_name: bch-dex
environment:
CONSUMER_URL: 'https://free-bch.fullstack.cash'
@@ -94,10 +94,10 @@ services:
restart: always
dex-ui:
build:
context: ./bch-dex-ui/
dockerfile: Dockerfile
#image: christroutner/bch-dex-ui:v1.2.4
#build:
# context: ./bch-dex-ui/
# dockerfile: Dockerfile
image: christroutner/bch-dex-ui:v1.2.4
container_name: dex-ui
environment:
SERVER: 'http://192.168.2.3'
+45 -1
View File
@@ -4,6 +4,7 @@
// Public npm libraries
import BchWallet from 'minimal-slp-wallet'
import BchTokenSweep from 'bch-token-sweep/index.js'
import bitcoinJs from 'bitcoincashjs-lib'
@@ -22,6 +23,8 @@ const WALLET_FILE = `${__dirname.toString()}/../../wallet.json`
// const P2WDB_TOKEN_ID =
// '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0'
const advancedConfig = {}
class WalletAdapter {
constructor (localConfig = {}) {
// Encapsulate dependencies
@@ -87,7 +90,7 @@ class WalletAdapter {
throw new Error('Wallet data is not formatted correctly. Can not read mnemonic in wallet file!')
}
const advancedConfig = {}
// const advancedConfig = {}
console.log(`Using FullStack.cash: ${this.config.useFullStackCash}`)
if (this.config.useFullStackCash) {
advancedConfig.interface = 'rest-api'
@@ -512,6 +515,47 @@ class WalletAdapter {
throw err
}
}
// Given an Order database object, this function sends the tokens from the
// HD index where they are stored, back to the root address of the wallet.
async reclaimTokens (orderData) {
try {
// Get the key pair from the Order.
const keyPair = await this.getKeyPair(orderData.hdIndex)
console.log('keyPair: ', keyPair)
// Instantiate the wallet using the private key of the Order.
// const tempWallet = new this.BchWallet(keyPair.wif, advancedConfig)
// await tempWallet.initialize()
// Send the tokens from the Order to the root address.
// const receiver = {
// address: this.bchWallet.walletInfo.address,
// tokenId: orderData.tokenId,
// qty: orderData.numTokens
// }
// console.log('receiver: ', receiver)
//
// const txid = await tempWallet.sendTokens(receiver)
// Sweep the tokens to the root address.
const sweeper = new BchTokenSweep(
keyPair.wif,
this.bchWallet.walletInfo.privateKey,
this.bchWallet,
550,
this.bchWallet.walletInfo.cashAddress
)
await sweeper.populateObjectFromNetwork()
const hex = await sweeper.sweepTo(this.bchWallet.walletInfo.cashAddress)
const txid = await this.bchWallet.ar.sendTx(hex)
return txid
} catch (err) {
console.error('Error in wallet.js/reclaimTokens()')
throw err
}
}
}
export default WalletAdapter
@@ -35,6 +35,7 @@ class OrderRESTControllerLib {
// console.log('body: ', ctx.request.body)
const orderObj = ctx.request.body.order
console.log('orderObj: ', orderObj)
const hash = await _this.useCases.order.createOrder(orderObj)
@@ -47,6 +48,41 @@ class OrderRESTControllerLib {
}
}
// curl -X GET http://localhost:5700/order/list/all/0
async listOrders (ctx) {
try {
let page = ctx.params.page
if (!page) page = 0
const offers = await _this.useCases.order.listOrders(page)
ctx.body = offers
} catch (err) {
console.log('Error in listOrders REST API handler: ', err)
_this.handleError(ctx, err)
}
}
// Delete an existing order by returning the token to the root address of
// the DEX wallet.
async deleteOrder (ctx) {
try {
// console.log('body: ', ctx.request.body)
const p2wdbHash = ctx.request.body.p2wdbHash
// console.log('p2wdbHash: ', p2wdbHash)
const txid = await _this.useCases.order.deleteOrder(p2wdbHash)
ctx.body = { txid }
} catch (err) {
// console.log(`err.message: ${err.message}`)
// console.log('err: ', err)
// ctx.throw(422, err.message)
_this.handleError(ctx, err)
}
}
// DRY error handler
handleError (ctx, err) {
console.log('err', err)
+2
View File
@@ -50,6 +50,8 @@ class OrderRouter {
// Define the routes and attach the controller.
this.router.post('/', _this.orderRESTController.createOrder)
this.router.get('/list/all/:page', _this.orderRESTController.listOrders)
this.router.post('/delete', _this.orderRESTController.deleteOrder)
// Attach the Controller routes to the Koa app.
app.use(_this.router.routes())
+39
View File
@@ -10,6 +10,8 @@ import wlogger from '../adapters/wlogger.js'
import OrderEntity from '../entities/order.js'
import config from '../../config/index.js'
const DEFAULT_ENTRIES_PER_PAGE = 20
class OrderLib {
constructor (localConfig = {}) {
// console.log('User localConfig: ', localConfig)
@@ -246,6 +248,43 @@ class OrderLib {
throw err
}
}
async listOrders (page = 0) {
try {
const data = await this.OrderModel.find({})
// Sort entries so newest entries show first.
.sort('-timestamp')
// Skip to the start of the selected page.
.skip(page * DEFAULT_ENTRIES_PER_PAGE)
// Only return 20 results.
.limit(DEFAULT_ENTRIES_PER_PAGE)
return data
} catch (error) {
console.error('Error in use-cases/order/listOrders()')
throw error
}
}
// Delete an Order model by sending the token back to the root address. This
// will allow the garbage collectors to delete the Order and the Offer.
async deleteOrder (p2wdbHash) {
try {
console.log('p2wdbHash: ', p2wdbHash)
// Find the order by the given hash.
const order = await this.findOrderByHash(p2wdbHash)
console.log('order: ', order)
// Reclaim the tokens
const txid = await this.adapters.wallet.reclaimTokens(order)
return txid
} catch (err) {
console.error('Error in use-cases/order/deleteOrder()')
throw err
}
}
}
export default OrderLib