mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
checking the 0x prefix on all the interaction with contracts
This commit is contained in:
parent
8a0679b2d4
commit
c57121e45b
@ -65,7 +65,7 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
let conditionIdEscrow: string
|
||||
|
||||
it("should register a DID", async () => {
|
||||
await keeper.didRegistry.registerAttribute(did.replace("0x", ""), checksum, url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, url, publisher.getId())
|
||||
})
|
||||
|
||||
it("should generate the condition IDs", async () => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Web3Provider from "../Web3Provider"
|
||||
import ContractBase from "./ContractBase"
|
||||
import { zeroX } from "../../utils"
|
||||
|
||||
export default class DIDRegistry extends ContractBase {
|
||||
|
||||
@ -10,14 +11,14 @@ export default class DIDRegistry extends ContractBase {
|
||||
}
|
||||
|
||||
public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string) {
|
||||
return this.send("registerAttribute", ownerAddress, ["0x" + did, Web3Provider.getWeb3().utils.fromAscii(checksum), value])
|
||||
return this.send("registerAttribute", ownerAddress, [zeroX(did), Web3Provider.getWeb3().utils.fromAscii(checksum), value])
|
||||
}
|
||||
|
||||
public async getDIDOwner(did: string): Promise<string> {
|
||||
return this.call("getDIDOwner", [did])
|
||||
return this.call("getDIDOwner", [zeroX(did)])
|
||||
}
|
||||
|
||||
public async getBlockNumberUpdated(did: string): Promise<number> {
|
||||
return +await this.call("getBlockNumberUpdated", [did])
|
||||
return +await this.call("getBlockNumberUpdated", [zeroX(did)])
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Condition } from "./Condition.abstract"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export class AccessSecretStoreCondition extends Condition {
|
||||
|
||||
@ -7,14 +8,14 @@ export class AccessSecretStoreCondition extends Condition {
|
||||
}
|
||||
|
||||
hashValues(did: string, grantee: string) {
|
||||
return super.hashValues(did, grantee)
|
||||
return super.hashValues(did, zeroX(grantee))
|
||||
}
|
||||
|
||||
fulfill(agreementId: string, did: string, grantee: string, from?: string) {
|
||||
return super.fulfill(agreementId, [did, grantee], from)
|
||||
return super.fulfill(agreementId, [did, grantee].map(zeroX), from)
|
||||
}
|
||||
|
||||
checkPermissions(grantee: string, did: string, from?: string) {
|
||||
return this.call<boolean>("checkPermissions", [grantee, did], from)
|
||||
return this.call<boolean>("checkPermissions", [grantee, did].map(zeroX), from)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import ContractBase from "../ContractBase"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export enum ConditionState {
|
||||
Uninitialized = 0,
|
||||
@ -26,7 +27,7 @@ export abstract class Condition extends ContractBase {
|
||||
|
||||
fulfill(agreementId: string, ...args: any[])
|
||||
fulfill(agreementId: string, args: any[], from?: string) {
|
||||
return this.sendFrom("fulfill", [agreementId, ...args], from)
|
||||
return this.sendFrom("fulfill", [zeroX(agreementId), ...args], from)
|
||||
}
|
||||
|
||||
async generateIdHash(agreementId: string, ...values: any[]) {
|
||||
@ -34,10 +35,10 @@ export abstract class Condition extends ContractBase {
|
||||
}
|
||||
|
||||
generateId(agreementId: string, valueHash: string) {
|
||||
return this.call<string>("generateId", [agreementId, valueHash])
|
||||
return this.call<string>("generateId", [zeroX(agreementId), valueHash])
|
||||
}
|
||||
|
||||
abortByTimeOut(agreementId: string, from?: string) {
|
||||
return this.sendFrom("requestTokens", [agreementId], from)
|
||||
return this.sendFrom("requestTokens", [zeroX(agreementId)], from)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Condition } from "./Condition.abstract"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export class EscrowReward extends Condition {
|
||||
|
||||
@ -7,7 +8,7 @@ export class EscrowReward extends Condition {
|
||||
}
|
||||
|
||||
hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) {
|
||||
return super.hashValues(amount, receiver, sender, lockCondition, releaseCondition)
|
||||
return super.hashValues(amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX))
|
||||
}
|
||||
|
||||
fulfill(
|
||||
@ -19,6 +20,6 @@ export class EscrowReward extends Condition {
|
||||
releaseCondition: string,
|
||||
from?: string,
|
||||
) {
|
||||
return super.fulfill(agreementId, [amount, receiver, sender, lockCondition, releaseCondition], from)
|
||||
return super.fulfill(agreementId, [amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX)], from)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Condition } from "./Condition.abstract"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export class LockRewardCondition extends Condition {
|
||||
|
||||
@ -7,10 +8,10 @@ export class LockRewardCondition extends Condition {
|
||||
}
|
||||
|
||||
hashValues(rewardAddress: string, amount: number) {
|
||||
return super.hashValues(rewardAddress, amount)
|
||||
return super.hashValues(zeroX(rewardAddress), amount)
|
||||
}
|
||||
|
||||
fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) {
|
||||
return super.fulfill(agreementId, [rewardAddress, amount], from)
|
||||
return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Logger from "../../../utils/Logger"
|
||||
import ContractBase from "../ContractBase"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export enum TemplateState {
|
||||
Uninitialized = 0,
|
||||
@ -35,7 +36,7 @@ export class TemplateStoreManager extends ContractBase {
|
||||
throw new Error("Template already exist.")
|
||||
}
|
||||
} else {
|
||||
return this.sendFrom("proposeTemplate", [address], from)
|
||||
return this.sendFrom("proposeTemplate", [zeroX(address)], from)
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,16 +48,16 @@ export class TemplateStoreManager extends ContractBase {
|
||||
throw new Error(`Template not in "proposed" state.`)
|
||||
}
|
||||
} else {
|
||||
return this.sendFrom("approveTemplate", [address], from)
|
||||
return this.sendFrom("approveTemplate", [zeroX(address)], from)
|
||||
}
|
||||
}
|
||||
|
||||
public revokeTemplate(address: string, from?: string) {
|
||||
return this.sendFrom("revokeTemplate", [address], from)
|
||||
return this.sendFrom("revokeTemplate", [zeroX(address)], from)
|
||||
}
|
||||
|
||||
public async getTemplate(address: string) {
|
||||
const {state, owner, lastUpdatedBy, blockNumberUpdated} = await this.call("getTemplate", [address])
|
||||
const {state, owner, lastUpdatedBy, blockNumberUpdated} = await this.call("getTemplate", [zeroX(address)])
|
||||
return {state: +state, owner, lastUpdatedBy, blockNumberUpdated: +blockNumberUpdated} as TemplateMetadata
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import ContractBase from "../ContractBase"
|
||||
import { Condition } from "../conditions/Condition.abstract"
|
||||
import Keeper from "../../Keeper"
|
||||
import { zeroX } from "../../../utils"
|
||||
|
||||
export abstract class AgreementTemplate extends ContractBase {
|
||||
|
||||
@ -28,9 +29,9 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
return this.sendFrom(
|
||||
"createAgreement",
|
||||
[
|
||||
agreementId,
|
||||
did,
|
||||
conditionIds,
|
||||
zeroX(agreementId),
|
||||
zeroX(did),
|
||||
conditionIds.map(zeroX),
|
||||
timeLocks,
|
||||
timeOuts,
|
||||
...extraArgs,
|
||||
|
Loading…
Reference in New Issue
Block a user