Skip to content
Snippets Groups Projects
Commit a4c9f2e8 authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Adding discard command to Sidenor CLI

parent 67f305ae
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@ const {
sendToCone,
sendToStock,
acceptBid,
rejectBid
rejectBid,
discardStock
} = require("./lib")
const program = createCLIApp()
......@@ -63,14 +64,14 @@ program
)
.action(loginAndCallAfterwards(rejectBid))
/*program
program
.command("discard-stock")
.description("Discard part of a slag stock")
.description("Discard part of a slag stock sending it to the landfill")
.option("--asset-id [value]", "Identifier of the slag stock")
.option(
"--quantity [value]",
"Quantity of the bidder for the provided slag stock"
"Quantity of the slag stock to discard (i.e., to be sent to the landfill)"
)
.action(loginAndCallAfterwards(discardStock))*/
.action(loginAndCallAfterwards(discardStock))
program.parse(process.argv)
......@@ -218,6 +218,55 @@ const bidResponse =
const acceptBid = bidResponse("accept")
const rejectBid = bidResponse("reject")
const discardStock = async (apiClient, { assetId: paramAssetId, quantity }) => {
const discadableAssets = await apiClient.richQuery({
fields: {
status: STATUSES.STOCK
}
})
const assetId = paramAssetId || (await promptAssetSelection(discadableAssets))
const assetToDiscard = discadableAssets.find(({ id }) => id === assetId)
let chosenQuantity = quantity
if (!quantity) {
const { inputQuantity } = await inquirer.prompt([
{
type: "number",
name: "inputQuantity",
message: `Choose an ammount of slag (max: ${assetToDiscard.quantity} ${assetToDiscard.units}):`,
default: Math.floor(assetToDiscard.quantity * 0.1) // Default: 10%
}
])
chosenQuantity = inputQuantity
}
const newAssets = await apiClient.splitAsset(assetId, 2, {
archiveOld: true,
bidirectional: true,
base: {
type: assetToDiscard.type,
fields: assetToDiscard.fields
}
})
await apiClient.modifyAsset({
id: newAssets[0],
quantity: assetToDiscard.quantity - chosenQuantity,
units: assetToDiscard.units
})
await apiClient.modifyAsset({
id: newAssets[1],
quantity: chosenQuantity,
units: assetToDiscard.units
})
await apiClient.deleteAsset(newAssets[1])
console.log(`Discarded stock ${newAssets[1]} (new stock ${newAssets[0]})`)
}
// To be reused as a library in @hypercog/batch-sim
module.exports = {
createAsset,
......@@ -225,5 +274,6 @@ module.exports = {
sendToCone,
sendToStock,
acceptBid,
rejectBid
rejectBid,
discardStock
}
......@@ -9,7 +9,7 @@
"version": "0.0.1",
"dependencies": {
"@faker-js/faker": "^5.5.3",
"@traceblock/api-client": "^0.2.5",
"@traceblock/api-client": "^0.2.9",
"commander": "^9.0.0",
"dotenv": "^16.0.0",
"inquirer": "^8.2.0"
......@@ -21,9 +21,9 @@
"integrity": "sha512-R11tGE6yIFwqpaIqcfkcg7AICXzFg14+5h5v0TfF/9+RMDL6jhzCy/pxHVOfbALGdtVYdt6JdR21tuxEgl34dw=="
},
"node_modules/@traceblock/api-client": {
"version": "0.2.5",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.5.tgz",
"integrity": "sha1-Sy3RTiEYWX+a/znrYDOkRuT9Z8E=",
"version": "0.2.9",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.9.tgz",
"integrity": "sha1-AhqCJayB7TK8tJ6LzvGzJszp1E8=",
"dependencies": {
"cross-fetch": "^3.1.4",
"jsonwebtoken": "^8.5.1"
......@@ -709,9 +709,9 @@
"integrity": "sha512-R11tGE6yIFwqpaIqcfkcg7AICXzFg14+5h5v0TfF/9+RMDL6jhzCy/pxHVOfbALGdtVYdt6JdR21tuxEgl34dw=="
},
"@traceblock/api-client": {
"version": "0.2.5",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.5.tgz",
"integrity": "sha1-Sy3RTiEYWX+a/znrYDOkRuT9Z8E=",
"version": "0.2.9",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.9.tgz",
"integrity": "sha1-AhqCJayB7TK8tJ6LzvGzJszp1E8=",
"requires": {
"cross-fetch": "^3.1.4",
"jsonwebtoken": "^8.5.1"
......
......@@ -3,7 +3,7 @@
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"@traceblock/api-client": "^0.2.5",
"@traceblock/api-client": "^0.2.9",
"@faker-js/faker": "^5.5.3",
"commander": "^9.0.0",
"dotenv": "^16.0.0",
......
......@@ -232,7 +232,7 @@ func (c BidDecisionController) _acceptBid(stub shared.LedgerBuildrStubInterface
splitParams.SplitConfig.ArchiveOld = true
splitParams.SplitConfig.Bidirectional = true
splitParams.SplitConfig.ChildCount = 2
splitParams.SplitConfig.BaseAsset.AssetType = "stocked"
splitParams.SplitConfig.BaseAsset.AssetType = biddableAsset.AssetType
subAssets, err := split.SplitAsset(c.TraceblockBaseController, stub, biddableAsset, *splitParams)
if err != nil {
......
......@@ -8,14 +8,14 @@
"name": "hypercog-config-scripts",
"version": "0.0.1",
"dependencies": {
"@traceblock/api-client": "^0.2.5",
"@traceblock/api-client": "^0.2.9",
"dotenv": "^10.0.0"
}
},
"node_modules/@traceblock/api-client": {
"version": "0.2.5",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.5.tgz",
"integrity": "sha1-Sy3RTiEYWX+a/znrYDOkRuT9Z8E=",
"version": "0.2.9",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.9.tgz",
"integrity": "sha1-AhqCJayB7TK8tJ6LzvGzJszp1E8=",
"dependencies": {
"cross-fetch": "^3.1.4",
"jsonwebtoken": "^8.5.1"
......@@ -168,9 +168,9 @@
},
"dependencies": {
"@traceblock/api-client": {
"version": "0.2.5",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.5.tgz",
"integrity": "sha1-Sy3RTiEYWX+a/znrYDOkRuT9Z8E=",
"version": "0.2.9",
"resolved": "https://artifact.tecnalia.com:443/artifactory/api/npm/traceblock-npm-release/@traceblock/api-client/-/api-client-0.2.9.tgz",
"integrity": "sha1-AhqCJayB7TK8tJ6LzvGzJszp1E8=",
"requires": {
"cross-fetch": "^3.1.4",
"jsonwebtoken": "^8.5.1"
......
......@@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@traceblock/api-client": "^0.2.5",
"@traceblock/api-client": "^0.2.9",
"dotenv": "^10.0.0"
},
"scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment