Select Git revision
entrypoint.sh
index.js 2.45 KiB
// COPYRIGHT: FUNDACIÓN TECNALIA RESEARCH & INNOVATION, 2022.
const { Option } = require("commander")
const { createCLIApp, HypercogApiClient } = require("@hypercog/utils")
const {
createAsset,
editComposition,
sendToCone,
sendToStock,
acceptBid
} = require("@hypercog/sidenor-cli")
const { bidAsset } = require("@hypercog/cement-cli")
const signInAs = async (apiClient, userMail, password) => {
const [username, organization] = userMail.split("@")
const okLogin = await apiClient.signIn(username, password, organization)
if (!okLogin) {
console.error("Unauthorized login")
return
}
}
const createAssetAndSendToCone = async (apiClient, name) => {
const assetId = await createAsset(apiClient, name)
await editComposition(apiClient, { assetId })
return sendToCone(apiClient, { assetId })
}
const simulateCycle = async (arg1, cmd) => {
const { api, network, channel, chaincode, password, ...otherArgs } =
cmd.parent.opts()
const apiClient = new HypercogApiClient(api, network, channel, chaincode)
await signInAs(apiClient, otherArgs.sidenorUser, password)
let batchId = await createAssetAndSendToCone(apiClient, "simulated asset 1")
batchId = await createAssetAndSendToCone(apiClient, "simulated asset 2")
batchId = await createAssetAndSendToCone(apiClient, "simulated asset 3")
const selectedStock = await sendToStock(apiClient, { assetId: batchId })
await signInAs(apiClient, otherArgs.cement1User, password)
await bidAsset(apiClient, {
assetId: selectedStock.id,
price: 2
})
await signInAs(apiClient, otherArgs.cement2User, password)
await bidAsset(apiClient, {
assetId: selectedStock.id,
quantity: selectedStock.quantity - 500,
price: 3
})
await signInAs(apiClient, otherArgs.sidenorUser, password)
await acceptBid(apiClient, { assetId: selectedStock.id })
}
const program = createCLIApp()
.addOption(
new Option(
"-su --sidenorUser <value>",
"User who will operate with blockchain as a steel manufacturer"
).env("SIDENOR_USER_ID")
)
.addOption(