Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 27 additions & 27 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
description = "Template for Holochain app development";

inputs = {
versions.url = "github:holochain/holochain?dir=versions/0_3_rc";
versions.inputs.holochain.url = "github:holochain/holochain/holochain-0.4.0-dev.2";
versions.url = "github:holochain/holochain?dir=versions/weekly";
versions.inputs.holochain.url = "github:holochain/holochain/holochain-0.4.0-dev.11";

holochain-flake.url = "github:holochain/holochain";
holochain-flake.inputs.versions.follows = "versions";
Expand All @@ -26,7 +26,7 @@
}: {

devShells.default = pkgs.mkShell {
inputsFrom = [ inputs'.holochain-flake.devShells.holonix ];
inputsFrom = [ inputs'.holochain-flake.devShells.holochainBinaries ];
packages = [
pkgs.nodejs-18_x
pkgs.binaryen
Expand Down
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
installApp,
enableApp,
appInfo,
dumpNetworkStats,
zomeCall
} from './utils'
import path from 'path'
Expand Down Expand Up @@ -184,6 +185,22 @@ export async function getArgs () {
logResult(result)
})

program
.command('dumpNetworkStats')
.alias('ns')
.description(
'dump network state for app: calls dumpNetworkStats() -> [DumpNetworkStats: any]'
)
.action(async () => {
const result = await call_admin_port(
dumpNetworkStats,
program.opts().adminPort,
)
console.log('Network State Dump for DNA:')
logResult(result)
})


program
.command('installApp <InstalledAppId> <AgentHash> <AppBundleSource>')
.alias('b')
Expand Down
75 changes: 14 additions & 61 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,67 +204,6 @@ export const listEnabledApps = async (adminWebsocket) => {
return result
}

/**
* Dumps state of holochain for given cell id in a pretty format
* @param {CellID | int} cellIdArg
* @returns string
*/
export const dumpState = async (adminWebsocket, cellIdArg) => {
console.log('cell Id Arg : ', cellIdArg)
if (!cellIdArg) throw new Error('No cell_id passed.')
let cellId

const index = parseInt(cellIdArg)
if (`${index}` === cellIdArg) {
// arg is a index so get cell ID list from conductor
const result = await adminWebsocket.listCellIds()
if (Array.isArray(result)) {
if (index >= result.length) {
return `CellId index (zero based) provided was ${index}, but there are only ${result.length} cell(s)`
}
cellId = result[index]
} else {
return `Expected array from listCellIds() got: ${result}`
}
} else {
// Convert cellIdArg into array format to satisfy dumpState arg type
cellId = cellIdArg.split(',')
if (Array.isArray(cellId)) {
cellId[0] = Buffer.from(cellId[0], 'base64')
cellId[1] = Buffer.from(cellId[1], 'base64')
} else {
throw new Error(
'Error parsing cell_id: cell_id should be an array [DnaHashBase64, AgentPubKeyBase64]'
)
}
}

console.log('CellId in Buffer format : ', cellId)
if (cellId.length !== 2) {
throw new Error(
'cell_id is in improper format. Make sure both the dna and agent hash are passed as a single, non-spaced array.'
)
} else if (cellId[0].length !== 39 || cellId[1].length !== 39) {
throw new Error(
'cell_id contains a hash of improper length. Make sure both the dna and agent hash are passed as a single, non-spaced array.'
)
}
let stateDump
try {
stateDump = await adminWebsocket.dumpState({
cell_id: cellId
})
} catch (error) {
throw new Error(`${JSON.stringify(error)}`)
}
// Replace all the buffers with byte64 representations
const result = stringifyBuffRec(stateDump)
return (
JSON.stringify(result, null, 4) +
`\n\nTotal Elements in Dump: ${stateDump.length}`
)
}

/**
* Call installApp for app bundle
* @param {obj} installAppArgs
Expand Down Expand Up @@ -371,3 +310,17 @@ export const zomeCall = async (appWebsocket, args) => {
}
return result
}

/**
* Dumps network state of holochain
* @returns string
*/
export const dumpNetworkStats = async (adminWebsocket) => {
let result
try {
result = await adminWebsocket.dumpNetworkStats()
} catch (error) {
return error
}
return result
}