mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge branch 'develop' into feature/Fix_Incorrect-datatype-for-amount-in-datatoken.transferFrom
This commit is contained in:
commit
8b275367a2
@ -19,7 +19,7 @@ before_script:
|
||||
- git clone https://github.com/oceanprotocol/barge
|
||||
- cd barge
|
||||
- git checkout v3
|
||||
- export PROVIDER_VERSION=phase2
|
||||
- export PROVIDER_VERSION=latest
|
||||
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
|
||||
- cd ..
|
||||
- sleep 300
|
||||
|
@ -6,24 +6,19 @@ const defaultDatatokensABI = require('@oceanprotocol/contracts/artifacts/develop
|
||||
*/
|
||||
export class DataTokens {
|
||||
public factoryAddress: string
|
||||
public factoryABI: object
|
||||
public datatokensABI: object
|
||||
public factoryABI: any
|
||||
public datatokensABI: any
|
||||
public web3: any
|
||||
|
||||
/**
|
||||
* Instantiate DataTokens (independently of Ocean).
|
||||
* @param {String} factoryAddress
|
||||
* @param {Object} factoryABI
|
||||
* @param {Object} datatokensABI
|
||||
* @param {Object} web3
|
||||
* @param {any} factoryABI
|
||||
* @param {any} datatokensABI
|
||||
* @param {any} web3
|
||||
|
||||
*/
|
||||
constructor(
|
||||
factoryAddress: string,
|
||||
factoryABI: object,
|
||||
datatokensABI: object,
|
||||
web3: any
|
||||
) {
|
||||
constructor(factoryAddress: string, factoryABI: any, datatokensABI: any, web3: any) {
|
||||
this.factoryAddress = factoryAddress
|
||||
this.factoryABI = factoryABI || defaultFactoryABI
|
||||
this.datatokensABI = datatokensABI || defaultDatatokensABI
|
||||
|
@ -76,12 +76,52 @@ export default class Account extends Instantiable {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Balance of Any Token.
|
||||
* @return {Promise<number>}
|
||||
* Balance of Any Token (converted from wei).
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
public async getTokenBalance(TokenAdress: string): Promise<number> {
|
||||
// TO DO
|
||||
return 0
|
||||
public async getTokenBalance(TokenAdress: string): Promise<string> {
|
||||
if (TokenAdress === null) return null
|
||||
const minABI = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [
|
||||
{
|
||||
name: '_owner',
|
||||
type: 'address'
|
||||
}
|
||||
],
|
||||
name: 'balanceOf',
|
||||
outputs: [
|
||||
{
|
||||
name: 'balance',
|
||||
type: 'uint256'
|
||||
}
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
]
|
||||
let result = null
|
||||
try {
|
||||
const token = new this.web3.eth.Contract(minABI as any, TokenAdress, {
|
||||
from: this.id
|
||||
})
|
||||
result = this.web3.utils.fromWei(
|
||||
await token.methods.balanceOf(this.id).call()
|
||||
)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Balance of Ocean Token. (converted from wei).
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
public async getOceanBalance(): Promise<string> {
|
||||
return this.getTokenBalance(this.config.oceanTokenAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,17 +134,11 @@ export default class Account extends Instantiable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Balance of Ether.
|
||||
* @return {Promise<number>}
|
||||
* Balance of Ether.(converted from wei).
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
public async getEtherBalance(): Promise<number> {
|
||||
// TO DO
|
||||
/* return this.web3.eth
|
||||
.getBalance(this.id, 'latest')
|
||||
.then((balance: string): number => {
|
||||
return new BigNumber(balance).toNumber()
|
||||
})
|
||||
*/
|
||||
return 0
|
||||
public async getEtherBalance(): Promise<string> {
|
||||
const result = await this.web3.eth.getBalance(this.id, 'latest')
|
||||
return this.web3.utils.fromWei(result)
|
||||
}
|
||||
}
|
||||
|
@ -31,21 +31,30 @@ export class Accounts extends Instantiable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account balance.
|
||||
* Return account balance for a given ERC20 token
|
||||
* @param {String} TokenAddress .
|
||||
* @param {Account} account Account instance.
|
||||
* @return {Promise<Balance>} Ether and Ocean Token balance.
|
||||
* @return {Promise<String>} Token balance.
|
||||
*/
|
||||
public balance(TokenAddress: string, account: Account): Promise<number> {
|
||||
public getTokenBalance(TokenAddress: string, account: Account): Promise<string> {
|
||||
return account.getTokenBalance(TokenAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account balance for a Ocean Tokens
|
||||
* @param {Account} account Account instance.
|
||||
* @return {Promise<String>} Ocean Token balance.
|
||||
*/
|
||||
public getOceanBalance(account: Account): Promise<string> {
|
||||
return account.getOceanBalance()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account balance in ETH
|
||||
* @param {Account} account Account instance.
|
||||
* @return {Promise<Balance>} Ether and Ocean Token balance.
|
||||
* @return {Promise<String>} Ether balance.
|
||||
*/
|
||||
public ETHbalance(account: Account): Promise<number> {
|
||||
public getEtherBalance(account: Account): Promise<string> {
|
||||
return account.getEtherBalance()
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,7 @@ import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
import { Ocean } from '../../src/ocean/Ocean'
|
||||
import config from './config'
|
||||
import { assert } from 'console'
|
||||
import { ComputeJob } from '../../src/ocean/interfaces/ComputeJob'
|
||||
import {
|
||||
Service,
|
||||
ServiceComputePrivacy,
|
||||
ServiceCompute
|
||||
} from '../../src/ddo/interfaces/Service'
|
||||
import { ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3('http://127.0.0.1:8545')
|
||||
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||
@ -23,11 +18,9 @@ describe('Compute flow', () => {
|
||||
let datasetNoRawAlgo
|
||||
let datasetWithTrustedAlgo
|
||||
let algorithmAsset
|
||||
let marketplace
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
let service1
|
||||
let price
|
||||
let ocean
|
||||
let computeService
|
||||
@ -73,7 +66,6 @@ describe('Compute flow', () => {
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
marketplace = (await ocean.accounts.list())[3]
|
||||
data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
|
Loading…
x
Reference in New Issue
Block a user