Compare commits

...
7 Commits
Author SHA1 Message Date
Chris Troutner 430f5f015e Merge pull request #284 from Permissionless-Software-Foundation/ct-unstable
fix(x402): Changing x402 default payment to 25,000 sats, so tx fee is 1%
2025-12-30 13:37:19 -07:00
Chris Troutner 9e76b34d05 fix(x402): Changing x402 default payment to 25,000 sats, so tx fee is 1% 2025-12-30 13:34:02 -07:00
Chris Troutner 61078b2e91 Merge pull request #283 from Permissionless-Software-Foundation/ct-unstable
fix(x402): Removing leading slash in payment URL
2025-12-29 17:08:41 -07:00
Chris Troutner 82733a7e1a Fixing tests 2025-12-29 17:04:09 -07:00
Chris Troutner 3685ea1541 fix(x402): Removing leading slash in payment URL 2025-12-29 16:43:40 -07:00
Chris Troutner 5f217af3e9 Merge pull request #282 from Permissionless-Software-Foundation/ct-unstable
fix(psf-slp-indexer): Fixing issue with error handling
2025-12-29 13:52:40 -07:00
Chris Troutner e2ca3cfb00 fix(psf-slp-indexer): Fixing issue with error handling 2025-12-29 12:38:30 -07:00
5 changed files with 33 additions and 26 deletions
+6 -6
View File
@@ -4298,9 +4298,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001761",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
"version": "1.0.30001762",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001762.tgz",
"integrity": "sha512-PxZwGNvH7Ak8WX5iXzoK1KPZttBXNPuaOvI2ZYU7NrlM+d9Ov+TUvlLOBNGzVXAntMSMMlJPd+jY6ovrVjSmUw==",
"funding": [
{
"type": "opencollective",
@@ -13491,9 +13491,9 @@
}
},
"node_modules/qs": {
"version": "6.14.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
"integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
"version": "6.14.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz",
"integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.1.0"
+5 -2
View File
@@ -86,7 +86,10 @@ class BCHJS {
} else if (process.env.BCHJSWIF && process.env.BCHJSWIF !== '') {
this.wif = process.env.BCHJSWIF
}
this.paymentAmountSats = (config && config.paymentAmountSats) || 2000 * 5
// Most TXs cost about 250 sats. So we'll set the default to 25000 sats,
// so the mining fee is 1% of the transaction.
this.paymentAmountSats = (config && config.paymentAmountSats) || 25000
// BCH server URL for x402 payments (separate from REST API server)
// This is used when broadcasting payment transactions to the blockchain
@@ -95,7 +98,7 @@ class BCHJS {
} else if (process.env.BCHJSBCHSERVERURL && process.env.BCHJSBCHSERVERURL !== '') {
this.bchServerURL = process.env.BCHJSBCHSERVERURL
} else {
this.bchServerURL = 'https://bch.fullstack.cash/v6/'
this.bchServerURL = 'https://bch.fullstack.cash/v6'
}
const libConfig = {
+5 -5
View File
@@ -66,7 +66,7 @@ class PsfSlpIndexer {
)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error)
else throw error
}
}
@@ -134,7 +134,7 @@ class PsfSlpIndexer {
}
throw new Error('Input address must be a string.')
} catch (error) {
if (error.response && error.response.data) throw error.response.data
if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error)
else throw error
}
}
@@ -199,7 +199,7 @@ class PsfSlpIndexer {
}
throw new Error('Input tokenId must be a string.')
} catch (error) {
if (error.response && error.response.data) throw error.response.data
if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error)
else throw error
}
}
@@ -427,7 +427,7 @@ class PsfSlpIndexer {
}
throw new Error('Input tokenId must be a string.')
} catch (error) {
if (error.response && error.response.data) throw error.response.data
if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error)
else throw error
}
}
@@ -522,7 +522,7 @@ class PsfSlpIndexer {
throw new Error('Input tokenId must be a string.')
} catch (error) {
// console.log('error: ', error)
if (error.response && error.response.data) throw error.response.data
if (error.response && error.response.data && error.response.data.error) throw new Error(error.response.data.error)
else throw error
}
}
+8 -8
View File
@@ -43,14 +43,14 @@ describe('#PsfSlpIndexer', () => {
try {
// Stub the network call.
const testErr = new Error()
testErr.response = { data: { status: 422 } }
testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'get').throws(testErr)
await bchjs.PsfSlpIndexer.status()
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(true, false, 'Unexpected result!')
} catch (err) {
assert.equal(err.status, 422)
assert.equal(err.message, 'Status 422')
}
})
})
@@ -103,7 +103,7 @@ describe('#PsfSlpIndexer', () => {
try {
// Stub the network call.
const testErr = new Error()
testErr.response = { data: { status: 422 } }
testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr)
const addr = 'bitcoincash:qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwywsf3583n'
@@ -112,7 +112,7 @@ describe('#PsfSlpIndexer', () => {
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(true, false, 'Unexpected result!')
} catch (err) {
assert.equal(err.status, 422)
assert.equal(err.message, 'Status 422')
}
})
})
@@ -174,7 +174,7 @@ describe('#PsfSlpIndexer', () => {
try {
// Stub the network call.
const testErr = new Error()
testErr.response = { data: { status: 422 } }
testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr)
const tokenId =
@@ -182,7 +182,7 @@ describe('#PsfSlpIndexer', () => {
await bchjs.PsfSlpIndexer.tokenStats(tokenId)
assert.equal(true, false, 'Unexpected result!')
} catch (err) {
assert.equal(err.status, 422)
assert.equal(err.message, 'Status 422')
}
})
})
@@ -399,7 +399,7 @@ describe('#PsfSlpIndexer', () => {
try {
// Stub the network call.
const testErr = new Error()
testErr.response = { data: { status: 422 } }
testErr.response = { data: { error: 'Status 422' } }
sandbox.stub(axios, 'post').throws(testErr)
const tokenId =
@@ -407,7 +407,7 @@ describe('#PsfSlpIndexer', () => {
await bchjs.PsfSlpIndexer.getTokenData(tokenId)
assert.equal(true, false, 'Unexpected result!')
} catch (err) {
assert.equal(err.status, 422)
assert.equal(err.message, 'Status 422')
}
})
})
+9 -5
View File
@@ -20,8 +20,10 @@ describe('#X402 Integration', () => {
})
assert.strictEqual(bchjs.wif, '')
assert.strictEqual(bchjs.paymentAmountSats, 10000)
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6/')
// assert.strictEqual(bchjs.paymentAmountSats, 10000)
assert.strictEqual(typeof bchjs.paymentAmountSats, 'number')
assert.ok(Number.isInteger(bchjs.paymentAmountSats) && bchjs.paymentAmountSats > 0)
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6')
})
it('should accept wif in config', () => {
@@ -59,8 +61,10 @@ describe('#X402 Integration', () => {
})
assert.strictEqual(bchjs.wif, '')
assert.strictEqual(bchjs.paymentAmountSats, 10000)
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6/')
// assert.strictEqual(bchjs.paymentAmountSats, 10000)
assert.strictEqual(typeof bchjs.paymentAmountSats, 'number')
assert.ok(Number.isInteger(bchjs.paymentAmountSats) && bchjs.paymentAmountSats > 0)
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6')
})
it('should read WIF from BCHJSWIF environment variable', () => {
@@ -168,7 +172,7 @@ describe('#X402 Integration', () => {
})
assert.strictEqual(bchjs.restURL, customRestURL)
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6/')
assert.strictEqual(bchjs.bchServerURL, 'https://bch.fullstack.cash/v6')
})
})