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

order fixes

This commit is contained in:
Bogdan Fazakas 2022-05-13 10:27:41 +03:00
parent 936985a0f8
commit be21be9559
4 changed files with 46 additions and 24 deletions

2
package-lock.json generated
View File

@ -41998,7 +41998,6 @@
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"decimal.js": "^10.3.1", "decimal.js": "^10.3.1",
"web3": "^1.7.3",
"web3-core": "^1.7.1", "web3-core": "^1.7.1",
"web3-eth-contract": "^1.7.1" "web3-eth-contract": "^1.7.1"
} }
@ -42050,7 +42049,6 @@
"integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==", "integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==",
"dev": true, "dev": true,
"requires": { "requires": {
"@oclif/config": "^1.18.2",
"@oclif/errors": "^1.3.5", "@oclif/errors": "^1.3.5",
"@oclif/help": "^1.0.1", "@oclif/help": "^1.0.1",
"@oclif/parser": "^3.8.6", "@oclif/parser": "^3.8.6",

View File

@ -135,6 +135,8 @@ export async function reuseOrder(
validOrderTx: string, validOrderTx: string,
providerFees?: ProviderFees providerFees?: ProviderFees
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
LoggerInstance.log('[compute] reuseOrder', providerFees)
const datatoken = new Datatoken(web3) const datatoken = new Datatoken(web3)
const initializeData = const initializeData =
!providerFees && !providerFees &&
@ -145,19 +147,26 @@ export async function reuseOrder(
accountId, accountId,
asset.services[0].serviceEndpoint asset.services[0].serviceEndpoint
)) ))
LoggerInstance.log('[compute] initializeData', initializeData)
const txApprove = await approve( if (
web3, providerFees?.providerFeeAmount ||
accountId, initializeData.providerFee.providerFeeToken
providerFees.providerFeeToken || ) {
initializeData.providerFee.providerFeeToken, const txApprove = await approve(
asset.accessDetails.datatoken.address, web3,
providerFees.providerFeeAmount || accountId,
initializeData.providerFee.providerFeeAmount, providerFees.providerFeeToken ||
false initializeData.providerFee.providerFeeToken,
) asset.accessDetails.datatoken.address,
if (!txApprove) { providerFees.providerFeeAmount,
return false
)
LoggerInstance.log('[compute] txApprove', txApprove)
if (!txApprove) {
return
}
} }
const tx = await datatoken.reuseOrder( const tx = await datatoken.reuseOrder(
@ -192,9 +201,16 @@ export async function handleComputeOrder(
initializeData: ProviderComputeInitialize, initializeData: ProviderComputeInitialize,
computeConsumerAddress?: string computeConsumerAddress?: string
): Promise<string> { ): Promise<string> {
LoggerInstance.log('[compute] handleComputeOrder asset: ', asset)
LoggerInstance.log(
'[compute] handleComputeOrder orderPriceAndFees: ',
orderPriceAndFees
)
if (initializeData.validOrder && !initializeData.providerFee) { if (initializeData.validOrder && !initializeData.providerFee) {
LoggerInstance.log('[compute] Has valid order: ', initializeData.validOrder)
return initializeData.validOrder return initializeData.validOrder
} else if (initializeData.validOrder) { } else if (initializeData.validOrder) {
LoggerInstance.log('[compute] Call reuse order', initializeData)
const tx = await reuseOrder( const tx = await reuseOrder(
web3, web3,
asset, asset,
@ -204,6 +220,7 @@ export async function handleComputeOrder(
) )
return tx.transactionHash return tx.transactionHash
} else { } else {
LoggerInstance.log('[compute] Call order', initializeData)
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') { if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3) const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3)
LoggerInstance.log('[compute] Buy dt from pool: ', poolTx) LoggerInstance.log('[compute] Buy dt from pool: ', poolTx)

View File

@ -8,7 +8,6 @@ import {
ProviderComputeInitializeResults, ProviderComputeInitializeResults,
ProviderInstance ProviderInstance
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { da } from 'date-fns/locale'
import { AssetExtended } from 'src/@types/AssetExtended' import { AssetExtended } from 'src/@types/AssetExtended'
import Web3 from 'web3' import Web3 from 'web3'
import { getValidUntilTime } from './compute' import { getValidUntilTime } from './compute'
@ -21,13 +20,13 @@ export async function initializeProviderForCompute(
): Promise<ProviderComputeInitializeResults> { ): Promise<ProviderComputeInitializeResults> {
const computeAsset: ComputeAsset = { const computeAsset: ComputeAsset = {
documentId: dataset.id, documentId: dataset.id,
serviceId: dataset.services[0].id, serviceId: dataset.services[0].id
transferTxId: dataset.accessDetails.validOrderTx // transferTxId: dataset.accessDetails.validOrderTx
} }
const computeAlgo: ComputeAlgorithm = { const computeAlgo: ComputeAlgorithm = {
documentId: algorithm.id, documentId: algorithm.id,
serviceId: algorithm.services[0].id, serviceId: algorithm.services[0].id
transferTxId: algorithm.accessDetails.validOrderTx // transferTxId: algorithm.accessDetails.validOrderTx
} }
const validUntil = getValidUntilTime( const validUntil = getValidUntilTime(

View File

@ -133,6 +133,7 @@ export default function Compute({
accountId, accountId,
computeEnv computeEnv
) )
console.log('initializedProvider == ', initializedProvider)
setInitializedProviderResponse(initializedProvider) setInitializedProviderResponse(initializedProvider)
// setIsProviderFeeValid( // setIsProviderFeeValid(
// await checkComputeResourcesValidity( // await checkComputeResourcesValidity(
@ -158,7 +159,9 @@ export default function Compute({
// setComputeValidUntil(validUntil) // setComputeValidUntil(validUntil)
if ( if (
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS || asset?.accessDetails?.addressOrId !== ZERO_ADDRESS ||
asset?.accessDetails?.type !== 'free' asset?.accessDetails?.type !== 'free' ||
(!initializedProvider.datasets[0].validOrder &&
initializedProvider.datasets[0].providerFee)
) { ) {
setIsRequestingDataseOrderPrice(true) setIsRequestingDataseOrderPrice(true)
setComputeStatusText( setComputeStatusText(
@ -190,6 +193,7 @@ export default function Compute({
poolParams, poolParams,
initializedProvider.datasets[0].providerFee initializedProvider.datasets[0].providerFee
) )
console.log('datasetPriceAndFees', datasetPriceAndFees)
if (!datasetPriceAndFees) { if (!datasetPriceAndFees) {
setError('Error setting dataset price and fees!') setError('Error setting dataset price and fees!')
toast.error('Error setting dataset price and fees!') toast.error('Error setting dataset price and fees!')
@ -201,7 +205,9 @@ export default function Compute({
if ( if (
selectedAlgorithmAsset?.accessDetails?.addressOrId !== ZERO_ADDRESS || selectedAlgorithmAsset?.accessDetails?.addressOrId !== ZERO_ADDRESS ||
selectedAlgorithmAsset?.accessDetails?.type !== 'free' selectedAlgorithmAsset?.accessDetails?.type !== 'free' ||
(!initializedProvider.algorithm.validOrder &&
initializedProvider.algorithm.providerFee)
) { ) {
setIsRequestingAlgoOrderPrice(true) setIsRequestingAlgoOrderPrice(true)
setComputeStatusText( setComputeStatusText(
@ -239,6 +245,7 @@ export default function Compute({
algoPoolParams, algoPoolParams,
initializedProvider.algorithm.providerFee initializedProvider.algorithm.providerFee
) )
console.log('algorithmOrderPriceAndFees', algorithmOrderPriceAndFees)
if (!algorithmOrderPriceAndFees) { if (!algorithmOrderPriceAndFees) {
setError('Error setting algorithm price and fees!') setError('Error setting algorithm price and fees!')
toast.error('Error setting algorithm price and fees!') toast.error('Error setting algorithm price and fees!')
@ -331,6 +338,7 @@ export default function Compute({
initializedProviderResponse.datasets[0], initializedProviderResponse.datasets[0],
computeEnv.consumerAddress computeEnv.consumerAddress
) )
console.log('datasetOrderTx', datasetOrderTx)
// if (isOwned) { // if (isOwned) {
// datasetOrderTx = validOrderTx // datasetOrderTx = validOrderTx
// LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx) // LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx)
@ -392,13 +400,13 @@ export default function Compute({
const algorithmOrderTx = await handleComputeOrder( const algorithmOrderTx = await handleComputeOrder(
web3, web3,
selectedAlgorithmAsset, selectedAlgorithmAsset,
datasetOrderPriceAndFees, algoOrderPriceAndFees,
accountId, accountId,
hasDatatoken, hasAlgoAssetDatatoken,
initializedProviderResponse.algorithm, initializedProviderResponse.algorithm,
computeEnv.consumerAddress computeEnv.consumerAddress
) )
console.log('algorithmOrderTx', algorithmOrderTx)
// if (isAlgorithmOwned) { // if (isAlgorithmOwned) {
// algorithmOrderTx = validAlgorithmOrderTx // algorithmOrderTx = validAlgorithmOrderTx
// LoggerInstance.log( // LoggerInstance.log(