Skip to content

Commit

Permalink
Updated satoshi-mediator to use keymaster SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 12, 2024
1 parent 47a4474 commit 68dbe3f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ services:
image: keychainmdip/satoshi-mediator
environment:
- KC_GATEKEEPER_URL=http://gatekeeper:4224
- KC_KEYMASTER_URL=http://keymaster:4226
- KC_NODE_ID=${KC_NODE_ID}
- KC_ENCRYPTED_PASSPHRASE=${KC_ENCRYPTED_PASSPHRASE}
- KC_SAT_CHAIN=TFTC
Expand All @@ -105,19 +106,20 @@ services:
depends_on:
- tftc-node
- gatekeeper
- keymaster

tbtc-node:
image: keychainmdip/bitcoin-core:v28.0
volumes:
- ./data/tbtc:/root/.bitcoin

tbtc-mediator:
build:
context: .
dockerfile: Dockerfile.satoshi
image: keychainmdip/satoshi-mediator
environment:
- KC_GATEKEEPER_URL=http://gatekeeper:4224
- KC_KEYMASTER_URL=http://keymaster:4226
- KC_NODE_ID=${KC_NODE_ID}
- KC_ENCRYPTED_PASSPHRASE=${KC_ENCRYPTED_PASSPHRASE}
- KC_SAT_CHAIN=TBTC
Expand All @@ -140,6 +142,7 @@ services:
depends_on:
- tbtc-node
- gatekeeper
- keymaster

ipfs-mediator:
build:
Expand Down
8 changes: 4 additions & 4 deletions packages/keymaster/src/db-wallet-cache.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
let actualWallet;
let baseWallet;
let cachedWallet;

export function setWallet(wallet) {
actualWallet = wallet;
baseWallet = wallet;
}

export function saveWallet(wallet, overwrite = false) {
cachedWallet = wallet;
return actualWallet.saveWallet(wallet, overwrite);
return baseWallet.saveWallet(wallet, overwrite);
}

export function loadWallet() {
if (!cachedWallet) {
cachedWallet = actualWallet.loadWallet();
cachedWallet = baseWallet.loadWallet();
}

return cachedWallet;
Expand Down
1 change: 1 addition & 0 deletions services/keymaster/server/src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ app.listen(port, async () => {

if (config.keymasterPassphrase) {
wallet_enc.setPassphrase(config.keymasterPassphrase);
wallet_enc.setWallet(wallet);
wallet = wallet_enc;
}

Expand Down
1 change: 1 addition & 0 deletions services/mediators/satoshi/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dotenv.config();
const config = {
nodeID: process.env.KC_NODE_ID,
gatekeeperURL: process.env.KC_GATEKEEPER_URL || 'http://localhost:4224',
keymasterURL: process.env.KC_KEYMASTER_URL,
keymasterPassphrase: process.env.KC_ENCRYPTED_PASSPHRASE,
chain: process.env.KC_SAT_CHAIN || 'BTC',
network: process.env.KC_SAT_NETWORK || 'mainnet',
Expand Down
40 changes: 28 additions & 12 deletions services/mediators/satoshi/src/satoshi-mediator.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import fs from 'fs';
import BtcClient from 'bitcoin-core';
import * as gatekeeper from '@mdip/gatekeeper/sdk';
import * as keymaster from '@mdip/keymaster/lib';
import * as keymaster_lib from '@mdip/keymaster/lib';
import * as keymaster_sdk from '@mdip/keymaster/sdk';
import * as wallet_json from '@mdip/keymaster/db/json';
import * as wallet_enc from '@mdip/keymaster/db/json/enc';
import * as cipher from '@mdip/cipher/node';
import config from './config.js';
import { InvalidParameterError } from '@mdip/common/errors';

const REGISTRY = config.chain;
let keymaster;

const client = new BtcClient({
network: config.network,
Expand Down Expand Up @@ -495,21 +497,35 @@ 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({
url: config.keymasterURL,
waitUntilReady: true,
intervalSeconds: 5,
chatty: true,
});
}
else {
keymaster = keymaster_lib;
await gatekeeper.start({
url: config.gatekeeperURL,
waitUntilReady: true,
intervalSeconds: 5,
chatty: true,
});

let wallet = wallet_json;

let wallet = wallet_json;
if (config.keymasterPassphrase) {
wallet_enc.setPassphrase(config.keymasterPassphrase);
wallet_enc.setWallet(wallet);
wallet = wallet_enc;
}

if (config.keymasterPassphrase) {
wallet_enc.setPassphrase(config.keymasterPassphrase);
wallet = wallet_enc;
await keymaster.start({ gatekeeper, wallet, cipher });
}

await keymaster.start({ gatekeeper, wallet, cipher });
await waitForNodeID();

if (config.importInterval > 0) {
Expand Down

0 comments on commit 68dbe3f

Please sign in to comment.