mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 01:02:00 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
075676aec1 | ||
|
|
f6646f8658 | ||
|
|
aa0a8a862c | ||
|
|
44c02beb3e | ||
|
|
10fb87d465 | ||
|
|
03942d5232 |
+1
-1
@@ -1,5 +1,5 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2021 Permissionless Software Foundation
|
||||
Copyright (c) 2022 Permissionless Software Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
Vendored
+7
-1
@@ -31,6 +31,12 @@ module.exports = {
|
||||
? process.env.EMAILPASS
|
||||
: 'emailpassword',
|
||||
|
||||
// PSF Web 3 community infrastructure
|
||||
useFullStackCash: process.env.USE_FULLSTACKCASH ? true : false,
|
||||
consumerUrl: process.env.CONSUMER_URL
|
||||
? process.env.CONSUMER_URL
|
||||
: 'https://free-bch.fullstack.cash',
|
||||
|
||||
// FullStack.cash account information, used for automatic JWT handling.
|
||||
getJwtAtStartup: process.env.GET_JWT_AT_STARTUP ? true : false,
|
||||
authServer: process.env.AUTHSERVER
|
||||
@@ -74,7 +80,7 @@ module.exports = {
|
||||
// P2WDB webhook endpoint
|
||||
webhookService: process.env.WEBHOOKSERVICE
|
||||
? process.env.WEBHOOKSERVICE
|
||||
: 'http://localhost:5001/webhook', // P2WDB.
|
||||
: 'http://localhost:5010/webhook', // P2WDB.
|
||||
|
||||
// IPFS Ports
|
||||
ipfsTcpPort: process.env.IPFS_TCP_PORT ? process.env.IPFS_TCP_PORT : 4001,
|
||||
|
||||
Generated
+26324
-207
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
||||
"test:all": "export BCH_DEX=test && nyc --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/",
|
||||
"test:unit": "export BCH_DEX=test && mocha --exit --timeout 15000 --recursive test/unit/",
|
||||
"test:e2e:auto": "export BCH_DEX=test && mocha --exit --timeout 15000 test/e2e/automated/",
|
||||
"test:integration": "export BCH_DEX=test && mocha --exit --timeout 30000 --recursive test/integration",
|
||||
"test:temp": "export BCH_DEX=test && mocha --exit --timeout 15000 -g '#rate-limit' test/unit/json-rpc/",
|
||||
"lint": "standard --env mocha --fix",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
||||
@@ -68,6 +69,7 @@
|
||||
"eslint-config-standard": "16.0.2",
|
||||
"eslint-plugin-node": "11.1.0",
|
||||
"eslint-plugin-prettier": "3.3.1",
|
||||
"eslint-plugin-promise": "^4.3.1",
|
||||
"eslint-plugin-standard": "4.0.0",
|
||||
"husky": "4.3.8",
|
||||
"mocha": "8.4.0",
|
||||
|
||||
@@ -72,7 +72,7 @@ class Adapters {
|
||||
}
|
||||
|
||||
// Start the IPFS node.
|
||||
await this.ipfs.start()
|
||||
// await this.ipfs.start()
|
||||
|
||||
// Open the wallet file
|
||||
const walletData = await this.wallet.openWallet()
|
||||
|
||||
+33
-25
@@ -7,6 +7,7 @@ const BchWallet = require('minimal-slp-wallet/index')
|
||||
|
||||
// Local libraries
|
||||
const JsonFiles = require('./json-files')
|
||||
const config = require('../../config')
|
||||
|
||||
const WALLET_FILE = `${__dirname.toString()}/../../wallet.json`
|
||||
const PROOF_OF_BURN_QTY = 0.01
|
||||
@@ -19,9 +20,12 @@ class WalletAdapter {
|
||||
this.jsonFiles = new JsonFiles()
|
||||
this.WALLET_FILE = WALLET_FILE
|
||||
this.BchWallet = BchWallet
|
||||
this.config = config
|
||||
}
|
||||
|
||||
// Open the wallet file, or create one if the file doesn't exist.
|
||||
// Does not instance the wallet. The output of this function is expected to
|
||||
// be passed to instanceWallet().
|
||||
async openWallet () {
|
||||
try {
|
||||
let walletData
|
||||
@@ -60,6 +64,35 @@ class WalletAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// Create an instance of minimal-slp-wallet. Use data in the wallet.json file,
|
||||
// and pass the bch-js information to the minimal-slp-wallet library.
|
||||
async instanceWallet (walletData) {
|
||||
try {
|
||||
// TODO: throw error if wallet data is not passed in.
|
||||
|
||||
const advancedConfig = {}
|
||||
if (this.config.useFullStackCash) {
|
||||
advancedConfig.interface = 'rest-api'
|
||||
advancedConfig.restURL = this.config.apiServer
|
||||
advancedConfig.apiToken = this.config.apiToken
|
||||
} else {
|
||||
advancedConfig.interface = 'consumer-api'
|
||||
advancedConfig.restURL = this.config.consumerUrl
|
||||
}
|
||||
|
||||
// Instantiate minimal-slp-wallet.
|
||||
this.bchWallet = new this.BchWallet(walletData.mnemonic, advancedConfig)
|
||||
|
||||
// Wait for wallet to initialize.
|
||||
await this.bchWallet.walletInfoPromise
|
||||
|
||||
return this.bchWallet
|
||||
} catch (err) {
|
||||
console.error('Error in instanceWallet()')
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Increments the 'nextAddress' property in the wallet file. This property
|
||||
// indicates the HD index that should be used to generate a key pair for
|
||||
// storing funds for Offers.
|
||||
@@ -124,31 +157,6 @@ class WalletAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// Create an instance of minimal-slp-wallet. Use data in the wallet.json file,
|
||||
// and pass the bch-js information to the minimal-slp-wallet library.
|
||||
async instanceWallet (walletData, bchjs) {
|
||||
try {
|
||||
// TODO: Throw error if bch-js is not passed in.
|
||||
// TODO: throw error if wallet data is not passed in.
|
||||
|
||||
const advancedConfig = {
|
||||
restURL: bchjs.restURL,
|
||||
apiToken: bchjs.apiToken
|
||||
}
|
||||
|
||||
// Instantiate minimal-slp-wallet.
|
||||
this.bchWallet = new this.BchWallet(walletData.mnemonic, advancedConfig)
|
||||
|
||||
// Wait for wallet to initialize.
|
||||
await this.bchWallet.walletInfoPromise
|
||||
|
||||
return true
|
||||
} catch (err) {
|
||||
console.error('Error in instanceWallet()')
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a cryptographic signature, required to write to the P2WDB.
|
||||
async generateSignature (message) {
|
||||
try {
|
||||
|
||||
@@ -32,7 +32,7 @@ class Controllers {
|
||||
// Attach the REST controllers to the Koa app.
|
||||
// this.attachRESTControllers(app)
|
||||
|
||||
this.attachRPCControllers()
|
||||
// this.attachRPCControllers()
|
||||
}
|
||||
|
||||
// Top-level function for this library.
|
||||
|
||||
@@ -57,7 +57,7 @@ class OfferLib {
|
||||
txid,
|
||||
signature,
|
||||
message,
|
||||
appId: 'swapTest555',
|
||||
appId: 'bch-dex-test556',
|
||||
data: offerEntity
|
||||
}
|
||||
|
||||
@@ -109,21 +109,21 @@ class OfferLib {
|
||||
|
||||
// Get UTXOs.
|
||||
const utxos = this.adapters.wallet.bchWallet.utxos.utxoStore
|
||||
// console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
||||
console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
||||
|
||||
if (offerEntity.buyOrSell.includes('sell')) {
|
||||
// Sell Offer
|
||||
|
||||
// Get token UTXOs that match the token in the offer.
|
||||
const tokenUtxos = utxos.slpUtxos.type1.tokens.filter(
|
||||
(x) => x.tokenId === offerEntity.tokenId
|
||||
x => x.tokenId === offerEntity.tokenId
|
||||
)
|
||||
// console.log('tokenUtxos: ', tokenUtxos)
|
||||
|
||||
// Get the total amount of tokens in the wallet that match the token
|
||||
// in the offer.
|
||||
let totalTokenBalance = 0
|
||||
tokenUtxos.map((x) => (totalTokenBalance += parseFloat(x.tokenQty)))
|
||||
tokenUtxos.map(x => (totalTokenBalance += parseFloat(x.tokenQty)))
|
||||
// console.log('totalTokenBalance: ', totalTokenBalance)
|
||||
|
||||
// If there are fewer tokens in the wallet than what's in the offer,
|
||||
@@ -135,6 +135,7 @@ class OfferLib {
|
||||
}
|
||||
} else {
|
||||
// Buy Offer
|
||||
throw new Error('Buy orders are not supported yet.')
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
const axios = require('axios')
|
||||
|
||||
const LOCALHOST = 'http://localhost:5700'
|
||||
const LOCALHOST = 'http://localhost:5002'
|
||||
|
||||
async function start () {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Integration tests for the wallet.js adapter library.
|
||||
*/
|
||||
|
||||
// Public npm libraries.
|
||||
const assert = require('chai').assert
|
||||
|
||||
// Local libraries.
|
||||
const WalletAdapter = require('../../../src/adapters/wallet')
|
||||
|
||||
describe('#wallet', () => {
|
||||
let uut
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new WalletAdapter()
|
||||
})
|
||||
|
||||
describe('#instanceWallet', () => {
|
||||
it('should instance the wallet using the web 3 infra by default', async () => {
|
||||
const walletData = await uut.openWallet()
|
||||
// console.log('walletData: ', walletData)
|
||||
|
||||
const walletInstance = await uut.instanceWallet(walletData)
|
||||
// console.log('walletInstance: ', walletInstance)
|
||||
|
||||
assert.equal(walletInstance.ar.interface, 'consumer-api')
|
||||
})
|
||||
|
||||
it('should instance using web 2 FullStack.cash infra', async () => {
|
||||
const walletData = await uut.openWallet()
|
||||
|
||||
// Force usage of FullStack.cash
|
||||
uut.config.useFullStackCash = true
|
||||
|
||||
const walletInstance = await uut.instanceWallet(walletData)
|
||||
// console.log('walletInstance: ', walletInstance)
|
||||
|
||||
assert.equal(walletInstance.ar.interface, 'rest-api')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -102,19 +102,15 @@ describe('#wallet', () => {
|
||||
// Mock dependencies
|
||||
uut.BchWallet = MockBchWallet
|
||||
|
||||
const bchjs = {
|
||||
restURL: 'dummyUrl',
|
||||
apiToken: 'dummyToken'
|
||||
}
|
||||
|
||||
// Ensure we open the test file, not the production wallet file.
|
||||
uut.WALLET_FILE = testWalletFile
|
||||
|
||||
const walletData = await uut.openWallet()
|
||||
|
||||
const result = await uut.instanceWallet(walletData.mnemonic, bchjs)
|
||||
const result = await uut.instanceWallet(walletData.mnemonic)
|
||||
console.log('result: ', result)
|
||||
|
||||
assert.equal(result, true)
|
||||
assert.property(result, 'walletInfoPromise')
|
||||
})
|
||||
|
||||
it('should catch and throw an error', async () => {
|
||||
|
||||
Reference in New Issue
Block a user