1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

finish start compute job

This commit is contained in:
Bogdan Fazakas 2022-02-03 15:43:27 +02:00
parent ff1f953ffe
commit ebcced9733
2 changed files with 335 additions and 95 deletions

101
package-lock.json generated
View File

@ -14929,7 +14929,104 @@
"bundleDependencies": [ "bundleDependencies": [
"source-map-support", "source-map-support",
"yargs", "yargs",
"ethereumjs-util" "ethereumjs-util",
"@types/bn.js",
"@types/node",
"@types/pbkdf2",
"@types/secp256k1",
"ansi-regex",
"ansi-styles",
"base-x",
"blakejs",
"bn.js",
"brorand",
"browserify-aes",
"bs58",
"bs58check",
"buffer-from",
"buffer-xor",
"camelcase",
"cipher-base",
"cliui",
"color-convert",
"color-name",
"create-hash",
"create-hmac",
"cross-spawn",
"decamelize",
"elliptic",
"emoji-regex",
"end-of-stream",
"ethereum-cryptography",
"ethjs-util",
"evp_bytestokey",
"execa",
"find-up",
"get-caller-file",
"get-stream",
"hash-base",
"hash.js",
"hmac-drbg",
"inherits",
"invert-kv",
"is-fullwidth-code-point",
"is-hex-prefixed",
"is-stream",
"isexe",
"keccak",
"lcid",
"locate-path",
"map-age-cleaner",
"md5.js",
"mem",
"mimic-fn",
"minimalistic-assert",
"minimalistic-crypto-utils",
"nice-try",
"node-addon-api",
"node-gyp-build",
"npm-run-path",
"once",
"os-locale",
"p-defer",
"p-finally",
"p-is-promise",
"p-limit",
"p-locate",
"p-try",
"path-exists",
"path-key",
"pbkdf2",
"pump",
"randombytes",
"readable-stream",
"require-directory",
"require-main-filename",
"ripemd160",
"rlp",
"safe-buffer",
"scrypt-js",
"secp256k1",
"semver",
"set-blocking",
"setimmediate",
"sha.js",
"shebang-command",
"shebang-regex",
"signal-exit",
"source-map",
"string_decoder",
"string-width",
"strip-ansi",
"strip-eof",
"strip-hex-prefix",
"util-deprecate",
"which",
"which-module",
"wrap-ansi",
"wrappy",
"y18n",
"yargs-parser"
], ],
"deprecated": "ganache-cli is now ganache; visit https://trfl.io/g7 for details", "deprecated": "ganache-cli is now ganache; visit https://trfl.io/g7 for details",
"dependencies": { "dependencies": {
@ -28995,7 +29092,6 @@
"cross-fetch": "^3.1.4", "cross-fetch": "^3.1.4",
"crypto-js": "^4.0.0", "crypto-js": "^4.0.0",
"decimal.js": "^10.2.1", "decimal.js": "^10.2.1",
"web3": ">=1.3.5",
"web3-core": "^1.6.1", "web3-core": "^1.6.1",
"web3-eth-contract": "^1.6.1" "web3-eth-contract": "^1.6.1"
} }
@ -29092,7 +29188,6 @@
"integrity": "sha512-5vwpq6kbvwkQwKqAoOU3L72GZ3Ta8RRrewKj9OJRolx28KLJJ8Dg9Rf7obRwt5jQA9bkYd8gqzMTrI7H3xLfaw==", "integrity": "sha512-5vwpq6kbvwkQwKqAoOU3L72GZ3Ta8RRrewKj9OJRolx28KLJJ8Dg9Rf7obRwt5jQA9bkYd8gqzMTrI7H3xLfaw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@oclif/config": "^1.15.1",
"@oclif/errors": "^1.3.3", "@oclif/errors": "^1.3.3",
"@oclif/parser": "^3.8.3", "@oclif/parser": "^3.8.3",
"@oclif/plugin-help": "^3", "@oclif/plugin-help": "^3",

View File

@ -7,7 +7,13 @@ import {
DDO, DDO,
PublisherTrustedAlgorithm, PublisherTrustedAlgorithm,
FileMetadata, FileMetadata,
Datatoken Datatoken,
ProviderInstance,
ProviderFees,
Pool,
OrderParams,
FreOrderParams,
ComputeAsset
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Price from '@shared/Price' import Price from '@shared/Price'
@ -39,6 +45,8 @@ import { useCancelToken } from '@hooks/useCancelToken'
import { useIsMounted } from '@hooks/useIsMounted' import { useIsMounted } from '@hooks/useIsMounted'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery' import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'
import { Decimal } from 'decimal.js' import { Decimal } from 'decimal.js'
import { TransactionReceipt } from 'web3-core'
import { useAbortController } from '@hooks/useAbortController'
export default function Compute({ export default function Compute({
ddo, ddo,
@ -62,6 +70,7 @@ export default function Compute({
const { buyDT, pricingError, pricingStepText } = usePricing() const { buyDT, pricingError, pricingStepText } = usePricing()
const [isJobStarting, setIsJobStarting] = useState(false) const [isJobStarting, setIsJobStarting] = useState(false)
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const newAbortController = useAbortController()
const [algorithmList, setAlgorithmList] = useState<AssetSelectionAsset[]>() const [algorithmList, setAlgorithmList] = useState<AssetSelectionAsset[]>()
const [ddoAlgorithmList, setDdoAlgorithmList] = useState<Asset[]>() const [ddoAlgorithmList, setDdoAlgorithmList] = useState<Asset[]>()
@ -257,8 +266,7 @@ export default function Compute({
const computeAlgorithm: ComputeAlgorithm = { const computeAlgorithm: ComputeAlgorithm = {
documentId: selectedAlgorithmAsset.id, documentId: selectedAlgorithmAsset.id,
serviceId: serviceAlgo.id serviceId: selectedAlgorithmAsset.services[0].id
// dataToken: selectedAlgorithmAsset.services[0].datatokenAddress
} }
const allowed = await isOrderable( const allowed = await isOrderable(
@ -279,8 +287,78 @@ export default function Compute({
return return
} }
if (!hasPreviousDatasetOrder && !hasDatatoken) { let assetOrderId = hasPreviousDatasetOrder ? previousDatasetOrderId : ''
const tx = await buyDT('1', price, ddo)
if (!hasPreviousDatasetOrder) {
const initializeData = await ProviderInstance.initialize(
ddo.id,
ddo.services[0].id,
0,
accountId,
ddo.services[0].serviceEndpoint //to check
)
const providerFees: ProviderFees = {
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
providerFeeToken: initializeData.providerFee.providerFeeToken,
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
v: initializeData.providerFee.v,
r: initializeData.providerFee.r,
s: initializeData.providerFee.s,
providerData: initializeData.providerFee.providerData,
validUntil: initializeData.providerFee.validUntil
}
if (!hasDatatoken) {
let tx: TransactionReceipt
switch (price?.type) {
case 'dynamic': {
// const poolInstance = new Pool(web3, LoggerInstance)
// const tx = poolInstance.
}
case 'fixed': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: price.address,
exchangeId: price.exchangeId,
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromFreAndOrder(
ddo.datatokens[0].address,
accountId,
order,
fre
)
assetOrderId = tx.transactionHash
}
case 'free': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 0,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: price.address,
exchangeId: price.exchangeId,
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromDispenserAndOrder(
ddo.datatokens[0].address,
accountId,
order,
price.address
)
assetOrderId = tx.transactionHash
}
}
if (!tx) { if (!tx) {
setError('Error buying datatoken.') setError('Error buying datatoken.')
LoggerInstance.error( LoggerInstance.error(
@ -289,102 +367,170 @@ export default function Compute({
) )
return return
} }
} else {
const datatokenInstance = new Datatoken(web3)
const tx = await datatokenInstance.startOrder(
ddo.datatokens[0].address,
accountId,
initializeData.computeAddress,
0,
providerFees
)
assetOrderId = tx.transactionHash
}
} }
if (!hasPreviousAlgorithmOrder && !hasAlgoAssetDatatoken) { let algorithmAssetOrderId = hasPreviousAlgorithmOrder
const tx = await buyDT('1', algorithmPrice, selectedAlgorithmAsset) ? previousAlgorithmOrderId
if (!tx) { : ''
setError('Error buying datatoken.')
LoggerInstance.error( // add method for this logic
'[compute] Error buying datatoken for algorithm ', if (!hasPreviousAlgorithmOrder) {
selectedAlgorithmAsset.id const initializeData = await ProviderInstance.initialize(
selectedAlgorithmAsset.id,
selectedAlgorithmAsset.services[0].id,
0,
accountId,
selectedAlgorithmAsset.services[0].serviceEndpoint //to check
) )
const providerFees: ProviderFees = {
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
providerFeeToken: initializeData.providerFee.providerFeeToken,
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
v: initializeData.providerFee.v,
r: initializeData.providerFee.r,
s: initializeData.providerFee.s,
providerData: initializeData.providerFee.providerData,
validUntil: initializeData.providerFee.validUntil
}
if (!hasAlgoAssetDatatoken) {
let tx: TransactionReceipt
switch (algorithmPrice?.type) {
case 'dynamic': {
// const poolInstance = new Pool(web3, LoggerInstance)
// const tx = poolInstance.
}
case 'fixed': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: price.address,
exchangeId: price.exchangeId,
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'), // to update
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromFreAndOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
order,
fre
)
algorithmAssetOrderId = tx.transactionHash
}
case 'free': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: price.address,
exchangeId: price.exchangeId,
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'), // to update
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromDispenserAndOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
order,
price.address
)
algorithmAssetOrderId = tx.transactionHash
}
}
} else {
const datatokenInstance = new Datatoken(web3)
const tx = await datatokenInstance.startOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
initializeData.computeAddress,
0,
providerFees
)
algorithmAssetOrderId = tx.transactionHash
}
}
// TODO: pricingError is always undefined even upon errors during buyDT for whatever reason.
// So manually drop out above, but ideally could be replaced with this alone.
if (pricingError) {
setError(pricingError)
return return
} }
LoggerInstance.log(
`[compute] Got ${
hasPreviousDatasetOrder ? 'existing' : 'new'
} order ID for dataset: `,
assetOrderId
)
LoggerInstance.log(
`[compute] Got ${
hasPreviousAlgorithmOrder ? 'existing' : 'new'
} order ID for algorithm: `,
algorithmAssetOrderId
)
if (!assetOrderId || !algorithmAssetOrderId) {
setError('Error ordering assets.')
return
} }
// // TODO: pricingError is always undefined even upon errors during buyDT for whatever reason. computeAlgorithm.transferTxId = algorithmAssetOrderId
// // So manually drop out above, but ideally could be replaced with this alone. LoggerInstance.log('[compute] Starting compute job.')
// if (pricingError) {
// setError(pricingError)
// return
// }
// const assetOrderId = hasPreviousDatasetOrder const computeAsset: ComputeAsset = {
// ? previousDatasetOrderId documentId: ddo.id,
// : await ocean.compute.orderAsset( serviceId: ddo.services[0].id,
// accountId, transferTxId: assetOrderId
// ddo.id, }
// computeService.index, computeAlgorithm.transferTxId = algorithmAssetOrderId
// computeAlgorithm,
// appConfig.marketFeeAddress,
// undefined,
// null,
// false
// )
// assetOrderId && const output: ComputeOutput = {
// LoggerInstance.log( publishAlgorithmLog: true,
// `[compute] Got ${ publishOutput: true
// hasPreviousDatasetOrder ? 'existing' : 'new' }
// } order ID for dataset: `,
// assetOrderId
// )
// const algorithmAssetOrderId = hasPreviousAlgorithmOrder const response = await ProviderInstance.computeStart(
// ? previousAlgorithmOrderId ddo.services[0].serviceEndpoint,
// : await ocean.compute.orderAlgorithm( web3,
// algorithmId, accountId,
// serviceAlgo.type, 'env1',
// accountId, computeAsset,
// serviceAlgo.index, computeAlgorithm,
// appConfig.marketFeeAddress, newAbortController(),
// undefined, null,
// null, output
// false )
// )
// algorithmAssetOrderId && if (!response) {
// LoggerInstance.log( setError('Error starting compute job.')
// `[compute] Got ${ return
// hasPreviousAlgorithmOrder ? 'existing' : 'new' }
// } order ID for algorithm: `,
// algorithmAssetOrderId
// )
// if (!assetOrderId || !algorithmAssetOrderId) { LoggerInstance.log('[compute] Starting compute job response: ', response)
// setError('Error ordering assets.')
// return
// }
// computeAlgorithm.transferTxId = algorithmAssetOrderId await checkPreviousOrders(selectedAlgorithmAsset)
// LoggerInstance.log('[compute] Starting compute job.') await checkPreviousOrders(ddo)
setIsPublished(true)
// const output: ComputeOutput = {
// publishAlgorithmLog: true,
// publishOutput: true
// }
// const response = await ocean.compute.start(
// ddo.id,
// assetOrderId,
// ddo.services[0].datatokenAddress,
// account,
// computeAlgorithm,
// output,
// `${computeService.index}`,
// computeService.type
// )
// if (!response) {
// setError('Error starting compute job.')
// return
// }
// LoggerInstance.log('[compute] Starting compute job response: ', response)
// await checkPreviousOrders(selectedAlgorithmAsset)
// await checkPreviousOrders(ddo)
// setIsPublished(true)
} catch (error) { } catch (error) {
await checkPreviousOrders(selectedAlgorithmAsset) await checkPreviousOrders(selectedAlgorithmAsset)
await checkPreviousOrders(ddo) await checkPreviousOrders(ddo)
@ -394,7 +540,6 @@ export default function Compute({
setIsJobStarting(false) setIsJobStarting(false)
} }
} }
return ( return (
<> <>
<div className={styles.info}> <div className={styles.info}>