mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
35 lines
771 B
JavaScript
35 lines
771 B
JavaScript
const axios = require("axios")
|
|||
|
|
|
||
|
|
let _this
|
||
|
|
|
||
|
|
class Generating {
|
||
|
|
constructor(config) {
|
||
|
|
this.restURL = config.restURL
|
||
|
|
this.apiToken = config.apiToken
|
||
|
|
|
||
|
|
// Add JWT token to the authorization header.
|
||
|
|
this.axiosOptions = {
|
||
|
|
headers: {
|
||
|
|
authorization: `Token ${this.apiToken}`
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
_this = this
|
||
|
|
}
|
||
|
|
|
||
|
|
async generateToAddress(blocks, address, maxtries = 1000000) {
|
||
|
|
try {
|
||
|
|
const response = await axios.post(
|
||
|
|
`${this.restURL}generating/generateToAddress/${blocks}/${address}?maxtries=${maxtries}`,
|
||
|
|
_this.axiosOptions
|
||
|
|
)
|
||
|
|
return response.data
|
||
|
|
} catch (error) {
|
||
|
|
if (error.response && error.response.data) throw error.response.data
|
||
|
|
else throw error
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = Generating
|