1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Merge pull request #77 from oceanprotocol/feature/assetId-prefixed-with-0x

Make assetId always prefixed with "0x"
This commit is contained in:
Sebastian Gerske 2018-12-14 16:15:12 +01:00 committed by GitHub
commit 604433dc50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 23 deletions

View File

@ -15,21 +15,21 @@ export default class DIDRegistry extends ContractBase {
value: string, ownerAddress: string): Promise<Receipt> {
return this.send("registerAttribute",
ownerAddress, ["0x" + did, type, Web3Provider.getWeb3().utils.fromAscii(key), value],
ownerAddress, [did, type, Web3Provider.getWeb3().utils.fromAscii(key), value],
)
}
public async getOwner(did: string): Promise<string> {
return this.call("getOwner",
["0x" + did],
[did],
)
}
public async getUpdateAt(did: string): Promise<number> {
const blockNum = await this.call("getUpdateAt",
["0x" + did],
[did],
)
return parseInt(blockNum, 10)

View File

@ -12,7 +12,7 @@ export default class OceanMarket extends ContractBase {
// call functions (costs no gas)
public async isAssetActive(assetId: string): Promise<boolean> {
return this.call("checkAsset", ["0x" + assetId])
return this.call("checkAsset", [assetId])
}
public async verifyOrderPayment(orderId: string): Promise<boolean> {
@ -20,7 +20,7 @@ export default class OceanMarket extends ContractBase {
}
public async getAssetPrice(assetId: string): Promise<number> {
return this.call("getAssetPrice", ["0x" + assetId])
return this.call("getAssetPrice", [assetId])
.then((price: string) => new BigNumber(price).toNumber())
}
@ -33,6 +33,6 @@ export default class OceanMarket extends ContractBase {
}
public async register(assetId: string, price: number, publisherAddress: string): Promise<Receipt> {
return this.send("register", publisherAddress, ["0x" + assetId, price])
return this.send("register", publisherAddress, [assetId, price])
}
}

View File

@ -49,7 +49,7 @@ export default class ServiceAgreement extends ContractBase {
return this.send("executeAgreement", publisherAddress, [
serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes,
timeoutValues, serviceAgreementId, "0x" + did.replace("did:op:", ""),
timeoutValues, serviceAgreementId, did.replace("did:op:", ""),
])
}
}

View File

@ -14,7 +14,7 @@ export default class AccessConditions extends ContractBase {
public async grantAccess(serviceAgreementId: any, assetId: any, documentKeyId: any, publisherAddress: string)
: Promise<Receipt> {
return this.send("grantAccess", publisherAddress, [
serviceAgreementId, "0x" + assetId, "0x" + documentKeyId,
serviceAgreementId, assetId, documentKeyId,
])
}
}

View File

@ -12,7 +12,7 @@ export default class PaymentConditions extends ContractBase {
public async lockPayment(serviceAgreementId: string, assetId: string, price: number, consumerAddress: string)
: Promise<Receipt> {
return this.send("lockPayment", consumerAddress, [
serviceAgreementId, "0x" + assetId, price,
serviceAgreementId, assetId, price,
])
}
}

View File

@ -67,7 +67,7 @@ export default class Ocean {
const aquarius = AquariusProvider.getAquarius()
const brizo = BrizoProvider.getBrizo()
const assetId: string = IdGenerator.generateId()
const assetId: string = IdGenerator.generatePrefixedId()
const did: string = `did:op:${assetId}`
const accessServiceDefinitionId: string = "0"
const computeServiceDefintionId: string = "1"
@ -183,7 +183,8 @@ export default class Ocean {
event.listenOnce(async (data) => {
const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.serviceAgreementId)
await sa.payAsset(id,
await sa.payAsset(
id,
metadataService.metadata.base.price,
consumer,
)

View File

@ -111,9 +111,9 @@ export default class ServiceAgreementTemplate extends OceanBase {
case "price":
return metadata.base.price
case "assetId":
return "0x" + assetId
return assetId
case "documentKeyId":
return "0x" + assetId
return assetId
}
return null

View File

@ -85,7 +85,7 @@ describe("Aquarius", () => {
it("should store a ddo", async () => {
const did: string = `did:op:${IdGenerator.generateId()}`
const did: string = `did:op:${IdGenerator.generatePrefixedId()}`
const ddo: DDO = new DDO({
id: did,
})
@ -103,7 +103,7 @@ describe("Aquarius", () => {
it("should store a ddo", async () => {
const did: string = `did:op:${IdGenerator.generateId()}`
const did: string = `did:op:${IdGenerator.generatePrefixedId()}`
const ddo: DDO = new DDO({
id: did,
})

View File

@ -26,7 +26,7 @@ describe("DIDRegistry", () => {
it("should register an attribute in a new did", async () => {
const ownerAccount: Account = (await ocean.getAccounts())[0]
const did = IdGenerator.generateId()
const did = IdGenerator.generatePrefixedId()
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
const data = "my nice provider, is nice"
const receipt = await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
@ -37,7 +37,7 @@ describe("DIDRegistry", () => {
it("should register another attribute in the same did", async () => {
const ownerAccount: Account = (await ocean.getAccounts())[0]
const did = IdGenerator.generateId()
const did = IdGenerator.generatePrefixedId()
{
// register the first attribute
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
@ -62,7 +62,7 @@ describe("DIDRegistry", () => {
it("should get the owner of a did properly", async () => {
const ownerAccount: Account = (await ocean.getAccounts())[0]
const did = IdGenerator.generateId()
const did = IdGenerator.generatePrefixedId()
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
const data = "my nice provider, is nice"
await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
@ -74,7 +74,7 @@ describe("DIDRegistry", () => {
})
it("should get 0x00.. for a not registered did", async () => {
const owner = await didRegistry.getOwner("1234")
const owner = await didRegistry.getOwner("0x1234")
assert(owner === "0x0000000000000000000000000000000000000000")
})
@ -84,7 +84,7 @@ describe("DIDRegistry", () => {
it("should the block number of the last update of the did attribute", async () => {
const ownerAccount: Account = (await ocean.getAccounts())[0]
const did = IdGenerator.generateId()
const did = IdGenerator.generatePrefixedId()
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
const data = "my nice provider, is nice"
await didRegistry.registerAttribute(did, ValueType.DID, providerKey,

View File

@ -23,7 +23,7 @@ let consumerAccount: Account
let accessService: Service
let metaDataService: Service
const assetId: string = IdGenerator.generateId()
const assetId: string = IdGenerator.generatePrefixedId()
describe("ServiceAgreement", () => {
@ -44,7 +44,7 @@ describe("ServiceAgreement", () => {
accessService = {
type: "Access",
serviceDefinitionId: IdGenerator.generateId(),
serviceDefinitionId: "0",
templateId: serviceAgreementTemplate.getId(),
conditions,
} as Service

View File

@ -49,7 +49,7 @@ describe("ServiceAgreementTemplate", () => {
new ServiceAgreementTemplate(access)
assert(serviceAgreementTemplate)
const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generateId())
const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generatePrefixedId())
assert(conds)
})
})