1
0
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:
Pedro Gutiérrez 2019-03-04 14:34:24 +01:00 committed by Pedro Gutiérrez
parent 8a0679b2d4
commit c57121e45b
8 changed files with 28 additions and 21 deletions

View File

@ -65,7 +65,7 @@ describe("Register Escrow Access Secret Store Template", () => {
let conditionIdEscrow: string let conditionIdEscrow: string
it("should register a DID", async () => { 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 () => { it("should generate the condition IDs", async () => {

View File

@ -1,5 +1,6 @@
import Web3Provider from "../Web3Provider" import Web3Provider from "../Web3Provider"
import ContractBase from "./ContractBase" import ContractBase from "./ContractBase"
import { zeroX } from "../../utils"
export default class DIDRegistry extends ContractBase { 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) { 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> { 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> { public async getBlockNumberUpdated(did: string): Promise<number> {
return +await this.call("getBlockNumberUpdated", [did]) return +await this.call("getBlockNumberUpdated", [zeroX(did)])
} }
} }

View File

@ -1,4 +1,5 @@
import { Condition } from "./Condition.abstract" import { Condition } from "./Condition.abstract"
import { zeroX } from "../../../utils"
export class AccessSecretStoreCondition extends Condition { export class AccessSecretStoreCondition extends Condition {
@ -7,14 +8,14 @@ export class AccessSecretStoreCondition extends Condition {
} }
hashValues(did: string, grantee: string) { 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) { 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) { 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)
} }
} }

View File

@ -1,4 +1,5 @@
import ContractBase from "../ContractBase" import ContractBase from "../ContractBase"
import { zeroX } from "../../../utils"
export enum ConditionState { export enum ConditionState {
Uninitialized = 0, Uninitialized = 0,
@ -26,7 +27,7 @@ export abstract class Condition extends ContractBase {
fulfill(agreementId: string, ...args: any[]) fulfill(agreementId: string, ...args: any[])
fulfill(agreementId: string, args: any[], from?: string) { 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[]) { async generateIdHash(agreementId: string, ...values: any[]) {
@ -34,10 +35,10 @@ export abstract class Condition extends ContractBase {
} }
generateId(agreementId: string, valueHash: string) { 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) { abortByTimeOut(agreementId: string, from?: string) {
return this.sendFrom("requestTokens", [agreementId], from) return this.sendFrom("requestTokens", [zeroX(agreementId)], from)
} }
} }

View File

@ -1,4 +1,5 @@
import { Condition } from "./Condition.abstract" import { Condition } from "./Condition.abstract"
import { zeroX } from "../../../utils"
export class EscrowReward extends Condition { 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) { 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( fulfill(
@ -19,6 +20,6 @@ export class EscrowReward extends Condition {
releaseCondition: string, releaseCondition: string,
from?: 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)
} }
} }

View File

@ -1,4 +1,5 @@
import { Condition } from "./Condition.abstract" import { Condition } from "./Condition.abstract"
import { zeroX } from "../../../utils"
export class LockRewardCondition extends Condition { export class LockRewardCondition extends Condition {
@ -7,10 +8,10 @@ export class LockRewardCondition extends Condition {
} }
hashValues(rewardAddress: string, amount: number) { 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) { fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) {
return super.fulfill(agreementId, [rewardAddress, amount], from) return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from)
} }
} }

View File

@ -1,5 +1,6 @@
import Logger from "../../../utils/Logger" import Logger from "../../../utils/Logger"
import ContractBase from "../ContractBase" import ContractBase from "../ContractBase"
import { zeroX } from "../../../utils"
export enum TemplateState { export enum TemplateState {
Uninitialized = 0, Uninitialized = 0,
@ -35,7 +36,7 @@ export class TemplateStoreManager extends ContractBase {
throw new Error("Template already exist.") throw new Error("Template already exist.")
} }
} else { } 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.`) throw new Error(`Template not in "proposed" state.`)
} }
} else { } else {
return this.sendFrom("approveTemplate", [address], from) return this.sendFrom("approveTemplate", [zeroX(address)], from)
} }
} }
public revokeTemplate(address: string, from?: string) { public revokeTemplate(address: string, from?: string) {
return this.sendFrom("revokeTemplate", [address], from) return this.sendFrom("revokeTemplate", [zeroX(address)], from)
} }
public async getTemplate(address: string) { 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 return {state: +state, owner, lastUpdatedBy, blockNumberUpdated: +blockNumberUpdated} as TemplateMetadata
} }
} }

View File

@ -1,6 +1,7 @@
import ContractBase from "../ContractBase" import ContractBase from "../ContractBase"
import { Condition } from "../conditions/Condition.abstract" import { Condition } from "../conditions/Condition.abstract"
import Keeper from "../../Keeper" import Keeper from "../../Keeper"
import { zeroX } from "../../../utils"
export abstract class AgreementTemplate extends ContractBase { export abstract class AgreementTemplate extends ContractBase {
@ -28,9 +29,9 @@ export abstract class AgreementTemplate extends ContractBase {
return this.sendFrom( return this.sendFrom(
"createAgreement", "createAgreement",
[ [
agreementId, zeroX(agreementId),
did, zeroX(did),
conditionIds, conditionIds.map(zeroX),
timeLocks, timeLocks,
timeOuts, timeOuts,
...extraArgs, ...extraArgs,