Skip to content

feat: Remove use of deprecated functions #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"bitcoinjs-message": "^2.2.0",
"bmapjs": "^0.4.0-beta.21",
"boom": "^7.3.0",
"boostpow": "^1.5.0",
"boostpow": "^1.9.1",
"bsv": "^1.5.5",
"bsv-2": "npm:bsv@^2.0.10",
"bsv-message": "^1.0.3",
Expand Down
110 changes: 43 additions & 67 deletions src/boost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,7 @@ export function getBoostJobsFromTxHex(txhex: string): boost.BoostPowJob[] {

const tx = new bsv.Transaction(txhex)

var index = 0
var jobs: boost.BoostPowJob[] = []

for (let output of tx.outputs) {

let job = boost.BoostPowJob.fromTransaction(txhex, index)

index +=1

if (job) { jobs.push(job) }

}

return jobs

return Object.values(boost.transaction.fromTransaction(tx).jobs);
}

export async function fetch(txid: string): Promise<string> {
Expand Down Expand Up @@ -111,13 +97,13 @@ export async function getBoostJobsFromTxid(txid:string): Promise<boost.BoostPowJ

}

export async function getBoostProof(txid: string): Promise<{ proof: boost.BoostPowJobProof, tx_hex: string }> {
export async function getBoostProofs(txid: string): Promise<{ proofs: Record<number,boost.BoostPowJobProof>, tx_hex: string }> {

const tx_hex = await fetch(txid)
let proofs = boost.transaction.fromTransaction(new bsv.Transaction(tx_hex)).redemptions

let proof = boost.BoostPowJobProof.fromRawTransaction(tx_hex)

return { proof, tx_hex }
return { proofs, tx_hex }

}

Expand Down Expand Up @@ -206,13 +192,13 @@ export async function getBoostJob(txid: string): Promise<BoostJob> {

export async function importBoostProofByTxid(txid: string): Promise<any> {

const {proof, tx_hex} = await getBoostProof(txid)
const {proofs, tx_hex} = await getBoostProofs(txid)

if (!proof) {
if (Object.keys(proofs).length === 0) {
return
}

return importBoostProof(proof, tx_hex)
return importBoostProofs(proofs, tx_hex)

}

Expand Down Expand Up @@ -269,37 +255,38 @@ async function _importBoostProofFromTxHex(txhex: string, {trusted}: {trusted?: b
}

}
let txDetails = boost.transaction.fromTransaction(tx);

let proof = boost.BoostPowJobProof.fromRawTransaction(txhex)

if (!trusted) {

importBoostProofByTxid(tx.hash)

}

return importBoostProof(proof, txhex)
return importBoostProofs(txDetails.redemptions, txhex)

}

export async function importBoostProof(proof: boost.BoostPowJobProof, tx_hex: string): Promise<any> { // proof_record
export async function importBoostProofs(proofs: Record<number,boost.BoostPowJobProof>, tx_hex: string): Promise<Record<number,boost.BoostPowJobProof>> { // proof_record

if (!proof) { return }
if (Object.keys(proofs).length===0) { return }

const timestamp = proof.time ? new Date(proof.time.number * 1000) : new Date()
let proof_records : Record<number,boost.BoostPowJobProof>={}
Object.keys(proofs).forEach(async (vout) => {
const curProof = proofs[vout];
const timestamp = curProof.time ? new Date(curProof.time.number * 1000) : new Date()

let where = {
txid: proof.spentTxid,
vout: proof.spentVout
}

let job = await models.BoostJob.findOne({
let where = {
txid: curProof.spentTxid,
vout: curProof.spentVout
}
let job = await models.BoostJob.findOne({
where
})
if (!job) {

if (!job) {

await importBoostJobFromTxid(proof.spentTxid)
await importBoostJobFromTxid(curProof.spentTxid)

job = await models.BoostJob.findOne({
where
Expand All @@ -309,30 +296,25 @@ export async function importBoostProof(proof: boost.BoostPowJobProof, tx_hex: st

return
}


}

let proof_record = await models.BoostWork.findOne({
where: {
job_txid: proof.spentTxid
job_txid: curProof.spentTxid
}
})

if (job.spend_txid && proof_record) {

return proof_record

if(job.spend_txid && proof_record) {
proof_records[vout] = proof_record

} else {

if (!proof_record) {

log.info('boost.importBoostProof.recordNotFound', { spentTxid: proof.spentTxid })

if(!proof_record) {
log.info('boost.importBoostProof.recordNotFound', { spentTxid: curProof.spentTxid })
proof_record = await models.BoostWork.create({
job_txid: proof.spentTxid,
job_vout: proof.spentVout,
spend_txid: proof.txid,
spend_vout: proof.vin,
job_txid: curProof.spentTxid,
job_vout: curProof.spentVout,
spend_txid: curProof.txid,
spend_vout: curProof.vin,
content: job.content,
difficulty: job.difficulty,
tag: job.tag,
Expand All @@ -346,13 +328,10 @@ export async function importBoostProof(proof: boost.BoostPowJobProof, tx_hex: st
publish('powco', 'boostpow.proof.created', proof_record.toJSON());

}


job.spent = true;
job.spent_txid = proof.txid;
job.spent_vout = proof.vin;
job.spent_txid = curProof.txid;
job.spent_vout = curProof.vin;
await job.save()

if (config.get('amqp_enabled')) {


Expand All @@ -361,25 +340,22 @@ export async function importBoostProof(proof: boost.BoostPowJobProof, tx_hex: st
})

}

}

let jobRecord = await models.BoostJob.findOne({
where: {
txid: proof.spentTxid,
vout: proof.spentVout
txid: curProof.spentTxid,
vout: curProof.spentVout
}
})

jobRecord.spend_txid = proof.spentTxid
jobRecord.spend_vout = proof.spentVout
jobRecord.spent = true

await jobRecord.save()

jobRecord.spend_txid = curProof.spentTxid
jobRecord.spend_vout = curProof.spentVout
jobRecord.spent = true;
await jobRecord.save();
}
});

return proof_record
return proof_records

}

Expand Down
16 changes: 8 additions & 8 deletions src/importer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { BoostPowJob, BoostPowJobProof, bsv } from "boostpow";
import { BoostPowJob, BoostPowJobProof, bsv, transaction } from "boostpow";
import delay = require("delay");
import { importBoostProof } from "./boost";
import { importBoostProofs } from "./boost";
import { log } from "./log";

import models from "./models";
Expand All @@ -14,21 +14,21 @@ class Importer {

jobs: JobsMap = {};

async importProof(tx_hex: string): Promise<{job: BoostPowJob, proof: BoostPowJobProof}> {
async importProof(tx_hex: string): Promise<{job: BoostPowJob, proofs: Record<number,BoostPowJobProof>}> {

log.info('importer.importProof', { tx_hex })

const tx = new bsv.Transaction(tx_hex)

const proof = BoostPowJobProof.fromRawTransaction(tx_hex)
const proofs = transaction.fromTransaction(tx).redemptions;

if (!proof) { return }
if (Object.keys(proofs).length===0) { return }

const result = await importBoostProof(proof, tx_hex)
const result = await importBoostProofs(proofs, tx_hex)

log.info('importer.importProof.result', result.toJSON())
log.info('importer.importProof.results', result)

return { job: undefined, proof }
return { job: undefined, proofs }

}

Expand Down
6 changes: 3 additions & 3 deletions src/test/lib/boost_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe("Boost Utilities", () => {

it('#getBoostProof should return a proof given a txid', async () => {

const result = await boost.getBoostProof('d1d26fa621f87dfc82ed1d8aa765b35172d04b32297025e5fa4df8044a829f92')
expect(result.proof).not.to.be.undefined;
expect(result.proof).to.be.instanceOf(BoostPowJobProof)
const result = await boost.getBoostProofs('d1d26fa621f87dfc82ed1d8aa765b35172d04b32297025e5fa4df8044a829f92')

expect(Object.keys(result.proofs).length).to.be.equal(1)

})

Expand Down
4 changes: 2 additions & 2 deletions src/test/lib/importer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Unmined Jobs Processor', () => {

const proof_tx_hex = "0200000001e1fde36ac18ce289dd8ed07c90424690f75fd59772cc9ae9305a891ab08895d10000000098483045022100b8a9cae7d3346c7aca4344d4fc0cd17ee93e1ed713a7d05274a4182c43c207cd02205ccc0aebbe7794ffa0959b243f7fa07c68493bfa7040ae852dc255319fd3325d412102f70cba8dfa2f23705c012c50a520ac0ac0fe61d2aec04a8c0b804f613348906e04076302000485a3d062086dbfa8a17b639b16040fc53a2214e8ee1688b47895f0e485ea0167c4eada12f6c579ffffffff019a260000000000001976a914e8ee1688b47895f0e485ea0167c4eada12f6c57988ac00000000"

const { proof } = await importer.importProof(proof_tx_hex)
const { proofs } = await importer.importProof(proof_tx_hex)

const record = await models.BoostWork.findOne({
where: {
Expand All @@ -32,7 +32,7 @@ describe('Unmined Jobs Processor', () => {

expect(record.txid)

expect(proof)
expect(proofs)

})

Expand Down
6 changes: 4 additions & 2 deletions src/test/lib/multi_day_feed_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { get_multi_day_feed } from '../../feeds/multi_day_feed'
import { expect} from '../utils'
describe('Multi-Day Feed', () => {
import { expect } from '../utils'

describe('Multi-Day Feed', async () => {

it.skip('should return five segments of data, one for each of the past five days', async () => {

Expand All @@ -11,6 +12,7 @@ describe('Multi-Day Feed', () => {
//TODO: fix this test, the output of get_multi_day_feed does not contain ago
// for (let day of days) {

// for (let day of days) {
// expect(day.ago).to.be.equal(1)

// expect(day.rankings.length).to.be.greaterThan(0)
Expand Down
Loading