Skip to content

Commit

Permalink
RPC: ultralight_setNetworkStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Jul 10, 2024
1 parent 9a8f09b commit a8ee2d3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/cli/src/rpc/modules/ultralight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const methods = [
'ultralight_getNetworkStorageInfo',
'ultralight_getNetworkDBSize',
'ultralight_pruneNetworkDB',
'ultralight_setNetworkStorage',
]

export class ultralight {
Expand Down Expand Up @@ -68,6 +69,10 @@ export class ultralight {
[validators.networkId],
])
this.pruneNetworkDB = middleware(this.pruneNetworkDB.bind(this), 1, [[validators.networkId]])
this.setNetworkStorage = middleware(this.setNetworkStorage.bind(this), 2, [
[validators.networkId],
[validators.megabytes],
])
}
async methods() {
return methods
Expand Down Expand Up @@ -196,4 +201,20 @@ export class ultralight {
radius: '0x' + network.nodeRadius.toString(16),
}
}
async setNetworkStorage(params: [NetworkId, number]) {
const [networkId, maxStorage] = params
const network = this._client.networks.get(networkId)
if (!network) {
throw {
code: INTERNAL_ERROR,
message: `Invalid network id ${networkId}`,
}
}
await network.prune(maxStorage)
return {
maxStorage,
dbSize: await network.db.size(),
radius: '0x' + network.nodeRadius.toString(16),
}
}
}

0 comments on commit a8ee2d3

Please sign in to comment.