From 504c8658c845cdf63d6de9fb2ca508191866841a Mon Sep 17 00:00:00 2001 From: David McFadzean Date: Thu, 12 Dec 2024 16:17:59 -0500 Subject: [PATCH] Added createAsset to keymaster SDK --- docker-compose.yml | 1 + packages/keymaster/src/keymaster-sdk.js | 10 +++++++++ .../keymaster/server/src/keymaster-api.js | 4 ++-- .../mediators/satoshi/src/satoshi-mediator.js | 22 +++++++++---------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9d1d3d09..b5fca886 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,6 +112,7 @@ services: image: keychainmdip/bitcoin-core:v28.0 volumes: - ./data/tbtc:/root/.bitcoin + tbtc-mediator: build: context: . diff --git a/packages/keymaster/src/keymaster-sdk.js b/packages/keymaster/src/keymaster-sdk.js index 2de66a52..bbbfa012 100644 --- a/packages/keymaster/src/keymaster-sdk.js +++ b/packages/keymaster/src/keymaster-sdk.js @@ -316,6 +316,16 @@ export async function resolveDID(name) { } } +export async function createAsset(data, options = {}) { + try { + const response = await axios.post(`${URL}/api/v1/assets`, { data, options }); + return response.data.did; + } + catch (error) { + throwError(error); + } +} + export async function resolveAsset(name) { try { const response = await axios.get(`${URL}/api/v1/assets/${name}`); diff --git a/services/keymaster/server/src/keymaster-api.js b/services/keymaster/server/src/keymaster-api.js index 6b0947c5..0d1d11be 100644 --- a/services/keymaster/server/src/keymaster-api.js +++ b/services/keymaster/server/src/keymaster-api.js @@ -575,8 +575,8 @@ v1router.post('/schemas/:id/template/', async (req, res) => { v1router.post('/assets/', async (req, res) => { try { - const { asset, options } = req.body; - const did = await keymaster.createAsset(asset, options); + const { data, options } = req.body; + const did = await keymaster.createAsset(data, options); res.json({ did }); } catch (error) { res.status(500).send({ error: error.toString() }); diff --git a/services/mediators/satoshi/src/satoshi-mediator.js b/services/mediators/satoshi/src/satoshi-mediator.js index 67a9a183..63710ba1 100644 --- a/services/mediators/satoshi/src/satoshi-mediator.js +++ b/services/mediators/satoshi/src/satoshi-mediator.js @@ -134,8 +134,6 @@ async function importBatch(item) { return; } - console.log(JSON.stringify(item, null, 4)); - const batch = []; for (let i = 0; i < queue.length; i++) { @@ -153,8 +151,6 @@ async function importBatch(item) { }); } - // console.log(JSON.stringify(batch, null, 4)); - try { item.imported = await gatekeeper.importBatch(batch); item.processed = await gatekeeper.processEvents(); @@ -340,9 +336,10 @@ async function anchorBatch() { } const batch = await gatekeeper.getQueue(REGISTRY); - console.log(JSON.stringify(batch, null, 4)); if (batch.length > 0) { + console.log(JSON.stringify(batch, null, 4)); + const did = await keymaster.createAsset({ batch }, { registry: 'hyperswarm', controller: config.nodeID }); const txid = await createOpReturnTxn(did); @@ -369,7 +366,7 @@ async function anchorBatch() { } } else { - console.log('empty batch'); + console.log(`empty ${REGISTRY} queue`); } } @@ -497,6 +494,13 @@ async function main() { return; } + await gatekeeper.start({ + url: config.gatekeeperURL, + waitUntilReady: true, + intervalSeconds: 5, + chatty: true, + }); + if (config.keymasterURL) { keymaster = keymaster_sdk; await keymaster.start({ @@ -508,12 +512,6 @@ async function main() { } else { keymaster = keymaster_lib; - await gatekeeper.start({ - url: config.gatekeeperURL, - waitUntilReady: true, - intervalSeconds: 5, - chatty: true, - }); let wallet = wallet_json;