Skip to content

Commit

Permalink
Added createAsset to keymaster SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 12, 2024
1 parent 68dbe3f commit 504c865
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ services:
image: keychainmdip/bitcoin-core:v28.0
volumes:
- ./data/tbtc:/root/.bitcoin

tbtc-mediator:
build:
context: .
Expand Down
10 changes: 10 additions & 0 deletions packages/keymaster/src/keymaster-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 2 additions & 2 deletions services/keymaster/server/src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down
22 changes: 10 additions & 12 deletions services/mediators/satoshi/src/satoshi-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -369,7 +366,7 @@ async function anchorBatch() {
}
}
else {
console.log('empty batch');
console.log(`empty ${REGISTRY} queue`);
}
}

Expand Down Expand Up @@ -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({
Expand All @@ -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;

Expand Down

0 comments on commit 504c865

Please sign in to comment.