Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

config_develop.json
config_production.json
31 changes: 28 additions & 3 deletions app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const main = async function() {

let batch_divider = 1;

const queue = Queue(config.dbConnection);
const queue = await Queue(config.dbConnection);
const tezos = new TezosToolkit(config.rpcUrl);

const signer = await get_signing_key(config)
Expand Down Expand Up @@ -69,7 +69,31 @@ const main = async function() {
queue.save_state(ids, state).catch((err) => { console.error("Database error when setting", state, "on operation with ids:", JSON.stringify(ids)); });;
}

const health_check = async function() {
let tez_supply = 0;
try {
let mutez_supply = await tezos.tz.getBalance(address);
tez_supply = mutez_supply.shiftedBy(-6).toNumber();
} catch (err) {
console.log("An error has occurred while attempting to get tez balance; the node may be down or inaccessible.\n", err);
return false;
}

if (tez_supply > config.warnBelowTez) {
// all okay <3
await queue.kill_canaries(address);
} else {
console.warn(`Tez balance on account ${address} below warning threshold`);
}

return true;
};

const heartbeat = async function() {
if (!await health_check()) {
return true;
}

let ops = await queue.checkout(address, ~~(config.batchSize/batch_divider) + 1);
if (ops.length == 0) {
console.log("No pending operations for originator", address);
Expand All @@ -82,10 +106,11 @@ const main = async function() {
let rejected_ids = [];
await Promise.all(ops.map((operation) => {
let success = dispatch_command(operation.command, batch);
const id = config.dbConnection.databaseType == 'mongodb' && operation._id ? operation._id : operation.id
if (success) {
batched_ids.push(operation.id);
batched_ids.push(id);
} else {
rejected_ids.push(operation.id);
rejected_ids.push(id);
}
}));

Expand Down
27 changes: 27 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"batchSize": 110,
"confirmations": 1,
"privateKey": "edesk1P5sdYMCSjMQiWcP6xGrt8RFqA6UKGvnbwSKcW6mY7JkUYwwnGf2zi3UwYk96bTQz3Msp7g8PvbGZDPAaLa",
"rpcUrl": "https://ghostnet-archive.tzconnect.berlin/",
"pollingDelay": 10000,
"timeout": 300,
"dbConnection": {
"user": "joris",
"password": "",
"host": "localhost",
"port": 5432,
"database": "joris"
},
"handlers": {
"nft": {
"handler": "MultiassetHandler",
"args": {
"contract_address": "KT19ALA2kvWQeBRMc4B84zt3qUZfzYUymGoT"
}
},
"tez": {
"handler": "TezHandler",
"args": {}
}
}
}
5 changes: 5 additions & 0 deletions confloader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const require = createRequire(import.meta.url);
const CONFIG_PATH = '.'

export default function() {
let config_json = process.env.PEPPERMINT_CONFIG;
if(config_json) {
console.log(config_json);
return JSON.parse(config_json);
}
let profile = process.env.PEPPERMINT_PROFILE;
let config_filename = profile ? `config_${profile}.json` : 'config.json';
console.log(`Reading configuration from ${config_filename}...`);
Expand Down
16 changes: 16 additions & 0 deletions insert_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
insert into peppermint.operations (originator , command) values ('tz1Pw1WizZhFx3dz6mLh28g7ZS4GrLEXLhoe', '{"args": {"token_id": 2, "to_address": "tz2QA1mGkeibTakCrNbaEdVwsWFm2BELQnuv", "metadata_ipfs": "ipfs://QmQoV15JrBWB4NjBVUAzeTq6CZsmoWXnt9ABSmupcrd6dg"}, "name": "create_and_mint", "handler": "nft"}');


-- {
-- "originator": "tz1Pw1WizZhFx3dz6mLh28g7ZS4GrLEXLhoe",
-- "state": "pending",
-- "command": {
-- "args": {
-- "token_id": 2,
-- "to_address": "tz2QA1mGkeibTakCrNbaEdVwsWFm2BELQnuv",
-- "metadata_ipfs": "ipfs://QmQoV15JrBWB4NjBVUAzeTq6CZsmoWXnt9ABSmupcrd6dg"
-- },
-- "name": "create_and_mint",
-- "handler": "nft"
-- }
-- }
5 changes: 4 additions & 1 deletion operations/nft-multiasset.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//import { TezosToolkit } from "@taquito/taquito";
import { MichelsonMap, TezosPreapplyFailureError } from '@taquito/taquito'
import { char2Bytes } from '@taquito/utils'

import util from 'util'

// import { createRequire } from 'module'
// const require = createRequire(import.meta.url);

Expand All @@ -9,7 +12,7 @@ import { char2Bytes } from '@taquito/utils'

export default async function(tezos, { contract_address }) {
let nft_contract = await tezos.contract.at(contract_address);
console.log("token contract loaded", nft_contract.parameterSchema.ExtractSignatures());
console.log("token contract loaded", util.inspect(nft_contract.parameterSchema.ExtractSignatures(), {showHidden: false, depth: null, colors: true}));

let contract_ops = {
create_token: nft_contract.methods.create_token,
Expand Down
Loading