-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create lockup ranking API endpoint for content and user
- Loading branch information
1 parent
1ba6640
commit 5cf3319
Showing
15 changed files
with
759 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"version": 9, | ||
"compilerVersion": "1.19.0+commit.72eaeba", | ||
"contract": "Lockup", | ||
"md5": "c54afe5c905a671b9be3909711368949", | ||
"structs": [], | ||
"library": [], | ||
"alias": [], | ||
"abi": [ | ||
{ | ||
"type": "function", | ||
"name": "redeem", | ||
"index": 0, | ||
"params": [ | ||
{ | ||
"name": "sig", | ||
"type": "Sig" | ||
}, | ||
{ | ||
"name": "pubkey", | ||
"type": "PubKey" | ||
}, | ||
{ | ||
"name": "__scrypt_ts_txPreimage", | ||
"type": "SigHashPreimage" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "constructor", | ||
"params": [ | ||
{ | ||
"name": "pkhash", | ||
"type": "Ripemd160" | ||
}, | ||
{ | ||
"name": "lockUntilHeight", | ||
"type": "int" | ||
} | ||
] | ||
} | ||
], | ||
"stateProps": [], | ||
"buildType": "debug", | ||
"file": "file:///Users/guillaume/Desktop/powco/boostpow-api/artifacts/lockup.scrypt", | ||
"hex": "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000<pkhash><lockUntilHeight>610079040065cd1d9f690079547a75537a537a537a5179537a75527a527a7575615579014161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561040065cd1d9f6955796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a756105ffffffff009f69557961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a75615279a2695679a95179876957795779ac7777777777777777", | ||
"sourceMapFile": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
contract Lockup { | ||
int lockUntilHeight; | ||
Ripemd160 pkhash; | ||
constructor(Ripemd160 pkhash, int lockUntilHeight) { | ||
require(lockUntilHeight < 500000000); | ||
this.lockUntilHeight = lockUntilHeight; | ||
this.pkhash = pkhash; | ||
} | ||
public function redeem(Sig sig, PubKey pubkey, SigHashPreimage __scrypt_ts_txPreimage) { | ||
require(Tx.checkPreimageSigHashType(__scrypt_ts_txPreimage, SigHashType(b'41'))); | ||
require(SigHash.nLocktime(__scrypt_ts_txPreimage) < 500000000); | ||
require(SigHash.nSequence(__scrypt_ts_txPreimage) < 0xffffffff); | ||
require(SigHash.nLocktime(__scrypt_ts_txPreimage) >= this.lockUntilHeight); | ||
require(hash160(pubkey) == this.pkhash); | ||
require(checkSig(sig, pubkey)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[[],[[9,0,12,13]],[[2,0,14,21],[6,0,14,4]],[[2,0,17,12],[12,0,17,4]],[[2,0,19,4],[14,0,19,24],[24,0,19,16],[32,0,19,53],[36,0,19,36]],[[4,0,21,8],[12,0,21,15],[28,0,21,15],[30,0,21,33]],[[4,0,22,8],[8,0,22,13],[25,0,22,8],[27,0,22,31]],[[4,0,23,8],[8,0,23,13],[16,0,23,8],[18,0,23,22]],[],[[2,0,27,4],[18,0,27,11],[25,0,27,23],[29,0,27,18],[34,0,27,36],[41,0,27,28]],[],[[4,0,28,8],[19,0,28,24],[54,0,28,15],[56,0,28,35]],[[4,0,29,8],[19,0,29,24],[54,0,29,15],[56,0,29,35]],[[4,0,30,8],[19,0,31,21],[54,0,31,12],[57,0,31,33],[61,0,31,38]],[[4,0,34,8],[12,0,35,12],[20,0,35,20],[28,0,35,12],[31,0,35,31],[35,0,35,36]],[[4,0,39,8],[12,0,39,20],[20,0,39,15],[21,0,39,29],[26,0,39,34],[32,0,39,15]],[],[]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"success": true, | ||
"errors": [], | ||
"scryptfile": "lockup.scrypt", | ||
"sourceMapFile": "lockup.scrypt.map", | ||
"ctxMethods": [ | ||
"redeem" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require('dotenv').config() | ||
|
||
const { Listener } = require("bsv-spv"); | ||
|
||
const name = "lockup"; | ||
const ticker = "BSV"; | ||
const blockHeight = 807000; // Number. If negative then it's number from the tip. | ||
const dataDir = __dirname; | ||
const port = 8080; // Same as Masters port above | ||
const listener = new Listener({ name, ticker, blockHeight, dataDir }); | ||
|
||
const { connect } = require('amqplib') | ||
|
||
import { bsv } from "scrypt-ts" | ||
import axios from "axios" | ||
import { detectLockupFromTxHex } from "../src/contracts/lockup"; | ||
|
||
var amqp; | ||
|
||
async function startAmqp() { | ||
|
||
const connection = await connect(process.env.amqp_url) | ||
|
||
amqp = await connection.createChannel() | ||
|
||
await amqp.assertExchange('powco') | ||
|
||
} | ||
|
||
startAmqp() | ||
|
||
|
||
const onBlock = async ({ | ||
header, | ||
started, | ||
finished, | ||
size, | ||
height, | ||
txCount, | ||
transactions, | ||
startDate, | ||
}) => { | ||
for (const [index, tx, pos, len] of transactions) { | ||
|
||
const hex = tx.toHex() | ||
|
||
let [lockup, vout] = await detectLockupFromTxHex(hex) | ||
|
||
if(lockup){ | ||
|
||
try { | ||
|
||
const result = await axios.post('https://hls.pow.co/api/v1/contracts', { | ||
origin: `${tx.hash}_${vout}`, | ||
class_name: 'Lockup', | ||
props: { | ||
lockUntilHeight: lockup.lockUntilHeight, | ||
pkhash: lockup.pkhash | ||
} | ||
}) | ||
|
||
} catch (error) { | ||
|
||
console.log('ingest.lockup.error', error) | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} | ||
}; | ||
|
||
listener.on("mempool_tx", async ({ transaction, size }) => { | ||
|
||
try { | ||
|
||
const hex = transaction.toHex() | ||
|
||
let [lockup, vout] = await detectLockupFromTxHex(hex) | ||
|
||
if(lockup){ | ||
|
||
try { | ||
|
||
const result = await axios.post('https://hls.pow.co/api/v1/contracts', { | ||
origin: `${transaction.hash}_${vout}`, | ||
class_name: 'Lockup', | ||
props: { | ||
lockUntilHeight: lockup.lockUntilHeight, | ||
pkhash: lockup.pkhash | ||
} | ||
}) | ||
|
||
} catch (error) { | ||
|
||
console.log('ingest.lockup.error', error) | ||
|
||
} | ||
} | ||
|
||
|
||
} catch(error) { | ||
|
||
} | ||
|
||
}); | ||
listener.on("block_reorg", ({ height, hash }) => { | ||
// Re-org after height | ||
}); | ||
listener.on("block_saved", ({ height, hash }) => { | ||
listener.syncBlocks(onBlock); | ||
}); | ||
|
||
listener.syncBlocks(onBlock); | ||
listener.connect({ port }); |
Oops, something went wrong.