Change the type of the price of an asset to string.

This commit is contained in:
Pedro Gutiérrez 2019-05-23 11:52:36 +02:00 committed by Pedro Gutiérrez
parent 080299dbd8
commit 6fe8430b08
10 changed files with 22 additions and 118 deletions

80
package-lock.json generated
View File

@ -856,18 +856,11 @@
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dev": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"bip66": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz",
"integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"bl": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
@ -1871,16 +1864,6 @@
"integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==",
"dev": true
},
"drbg.js": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz",
"integrity": "sha1-Pja2xCs3BDgjzbwzLVjzHiRFSAs=",
"requires": {
"browserify-aes": "^1.0.6",
"create-hash": "^1.1.2",
"create-hmac": "^1.1.4"
}
},
"dtype": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dtype/-/dtype-2.0.0.tgz",
@ -2097,20 +2080,6 @@
"xhr-request-promise": "^0.1.2"
}
},
"ethereumjs-util": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz",
"integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==",
"requires": {
"bn.js": "^4.11.0",
"create-hash": "^1.1.2",
"ethjs-util": "0.1.6",
"keccak": "^1.0.2",
"rlp": "^2.0.0",
"safe-buffer": "^5.1.1",
"secp256k1": "^3.0.1"
}
},
"ethers": {
"version": "4.0.0-beta.1",
"resolved": "https://registry.npmjs.org/ethers/-/ethers-4.0.0-beta.1.tgz",
@ -2186,15 +2155,6 @@
}
}
},
"ethjs-util": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz",
"integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==",
"requires": {
"is-hex-prefixed": "1.0.0",
"strip-hex-prefix": "1.0.0"
}
},
"eventemitter3": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-1.1.1.tgz",
@ -2462,7 +2422,8 @@
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"dev": true
},
"fill-range": {
"version": "4.0.0",
@ -4306,17 +4267,6 @@
"verror": "1.10.0"
}
},
"keccak": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz",
"integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw==",
"requires": {
"bindings": "^1.2.1",
"inherits": "^2.0.3",
"nan": "^2.2.1",
"safe-buffer": "^5.1.0"
}
},
"keccakjs": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/keccakjs/-/keccakjs-0.2.3.tgz",
@ -5881,15 +5831,6 @@
"inherits": "^2.0.1"
}
},
"rlp": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.2.tgz",
"integrity": "sha512-Ng2kJEN731Sfv4ZAY2i0ytPMc0BbJKBsVNl0QZY8LxOWSwd+1xpg+fpSRfaMn0heHU447s6Kgy8qfHZR0XTyVw==",
"requires": {
"bn.js": "^4.11.1",
"safe-buffer": "^5.1.1"
}
},
"run-queue": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz",
@ -5972,21 +5913,6 @@
"pbkdf2": "^3.0.3"
}
},
"secp256k1": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.6.2.tgz",
"integrity": "sha512-90nYt7yb0LmI4A2jJs1grglkTAXrBwxYAjP9bpeKjvJKOjG2fOeH/YI/lchDMIvjrOasd5QXwvV2jwN168xNng==",
"requires": {
"bindings": "^1.2.1",
"bip66": "^1.1.3",
"bn.js": "^4.11.3",
"create-hash": "^1.1.2",
"drbg.js": "^1.0.1",
"elliptic": "^6.2.3",
"nan": "^2.2.1",
"safe-buffer": "^5.1.0"
}
},
"seek-bzip": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.5.tgz",

View File

@ -68,7 +68,6 @@
"@oceanprotocol/keeper-contracts": "^0.9.7",
"bignumber.js": "^8.1.1",
"deprecated-decorator": "^0.1.6",
"ethereumjs-util": "^6.1.0",
"node-fetch": "^2.3.0",
"save-file": "^2.3.1",
"uuid": "^3.3.2",

View File

@ -176,10 +176,10 @@ export interface MetaDataBase {
/**
* Price of the asset.
* @type {number}
* @example 10
* @type {string}
* @example "1000000000000000000"
*/
price: number
price: string
/**
* Array of File objects including the encrypted file urls and some additional information.

View File

@ -9,7 +9,7 @@ export default class Dispenser extends ContractBase {
return dispenser
}
public async requestTokens(amount: number, receiverAddress: string) {
return this.send("requestTokens", receiverAddress, [amount])
public async requestTokens(amount: number | string, receiverAddress: string) {
return this.send("requestTokens", receiverAddress, [String(amount)])
}
}

View File

@ -10,8 +10,8 @@ export default class OceanToken extends ContractBase {
return token
}
public async approve(to: string, price: number, from?: string) {
return this.sendFrom("approve", [to, price], from)
public async approve(to: string, price: number | string, from?: string) {
return this.sendFrom("approve", [to, String(price)], from)
}
public async decimals(): Promise<number> {

View File

@ -8,11 +8,11 @@ export class LockRewardCondition extends Condition {
return Condition.getInstance(config, "LockRewardCondition", LockRewardCondition)
}
public hashValues(rewardAddress: string, amount: number) {
return super.hashValues(zeroX(rewardAddress), amount)
public hashValues(rewardAddress: string, amount: number | string) {
return super.hashValues(zeroX(rewardAddress), String(amount))
}
public fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) {
return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from)
public fulfill(agreementId: string, rewardAddress: string, amount: number | string, from?: string) {
return super.fulfill(agreementId, [zeroX(rewardAddress), String(amount)], from)
}
}

View File

@ -69,7 +69,7 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
* @param {string} from Consumer address.
* @return {Promise<string>} Agreement ID.
*/
public async createFullAgreement(did: string, amount: number, consumer: string, from?: string, agreementId?: string): Promise<string> {
public async createFullAgreement(did: string, amount: number | string, consumer: string, from?: string, agreementId?: string): Promise<string> {
agreementId = agreementId || generateId()
const {accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId} =
await this.createFullAgreementData(agreementId, did, amount, consumer)
@ -87,7 +87,7 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
return zeroX(agreementId)
}
private async createFullAgreementData(agreementId: string, did: string, amount: number, consumer: string) {
private async createFullAgreementData(agreementId: string, did: string, amount: number | string, consumer: string) {
const {didRegistry, conditions} = this.ocean.keeper
const {accessSecretStoreCondition, lockRewardCondition, escrowReward} = conditions

View File

@ -1,5 +1,4 @@
import BigNumber from "bignumber.js"
import * as EthJsUtils from "ethereumjs-util"
import Balance from "../models/Balance"
import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
@ -79,7 +78,8 @@ export default class Account extends Instantiable {
* @param {number} amount Tokens to be requested.
* @return {Promise<number>}
*/
public async requestTokens(amount: number): Promise<number> {
public async requestTokens(amount: number | string): Promise<string> {
amount = String(amount)
try {
await this.ocean.keeper
.dispenser
@ -91,16 +91,4 @@ export default class Account extends Instantiable {
}
return amount
}
/**
* Returns the account public key.
* @return {Promise<string>}
*/
public async getPublicKey(): Promise<string> {
const msg = this.web3.utils.sha3(this.getId())
const sig = await this.web3.eth.sign(msg, this.getId())
const {v, r, s} = EthJsUtils.fromRpcSig(sig)
return EthJsUtils.ecrecover(EthJsUtils.toBuffer(msg), v, r, s).toString("hex")
}
}

View File

@ -24,7 +24,7 @@ export class OceanAgreementsConditions extends Instantiable {
* @param {number} amount Asset amount.
* @param {Account} from Account of sender.
*/
public async lockReward(agreementId: string, amount: number, from?: Account) {
public async lockReward(agreementId: string, amount: number | string, from?: Account) {
const {lockRewardCondition, escrowReward} = this.ocean.keeper.conditions
await this.ocean.keeper.token.approve(lockRewardCondition.getAddress(), amount, from.getId())

View File

@ -67,21 +67,12 @@ describe("Account", () => {
it("should return the amount of tokens granted", async () => {
const tokens = 500
const tokens = "500"
const account: Account = accounts[0]
const tokensGranted: number = await account.requestTokens(tokens)
const tokensGranted: string = await account.requestTokens(tokens)
assert(tokensGranted === tokens)
assert.equal(tokensGranted, tokens)
})
})
describe("#getPublicKey()", () => {
it("should get the public key of an account", async () => {
const publicKey = await accounts[1].getPublicKey()
assert(publicKey)
assert(publicKey.length === 128)
})
})
})