Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove proxyExists from ara-contracts #88

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ The contracts in this repository are deployed on [Ara Privatenet](https://github

### Registry

* [registry.proxyExists(contentDid)](#proxyexists)
* [registry.getProxyAddress(contentDid)](#getproxy)
* [registry.upgradeProxy(opts)](#upgrade)
* [registry.deployProxy(opts)](#deploy)
Expand Down Expand Up @@ -112,17 +111,6 @@ await purchase({
})
```

<a name="proxyexists"></a>
### `registry.proxyExists(contentDid)`

Checks if the proxy for a content `DID` exists.

- `contentDid` - The `DID` of the content to check

```js
const exists = await registry.proxyExists(contentDid)
```

<a name="getproxy"></a>
### `registry.getProxyAddress(contentDid)`

Expand Down
25 changes: 12 additions & 13 deletions commerce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { abi } = require('./build/contracts/AFS.json')
const { getProxyAddress } = require('./registry')
const hasDIDMethod = require('has-did-method')
const { AID_PREFIX } = require('./constants')

Expand All @@ -14,11 +15,6 @@ const {
}
} = require('ara-util')

const {
getProxyAddress,
proxyExists
} = require('./registry')

/**
* Requests ownership of an AFS.
* @param {Object} opts
Expand Down Expand Up @@ -103,11 +99,13 @@ async function approveOwnershipTransfer(opts) {
Ensure ${newOwnerDid} is a valid Ara identity.`)
}

if (!(await proxyExists(did))) {
throw new Error('Content does not have a valid proxy contract')
let proxy
try {
proxy = await getProxyAddress(did)
} catch (err) {
throw err
}

const proxy = await getProxyAddress(did)

let owner = getDocumentOwner(ddo, true)
owner = `${AID_PREFIX}${owner}`

Expand Down Expand Up @@ -170,12 +168,13 @@ async function _updateOwnershipRequest(opts, functionName = '') {
Ensure ${requesterDid} is a valid Ara identity.`)
}

if (!(await proxyExists(contentDid))) {
throw new Error('Content does not have a valid proxy contract')
let proxy
try {
proxy = await getProxyAddress(contentDid)
} catch (err) {
throw err
}

const proxy = await getProxyAddress(contentDid)

if (!hasDIDMethod(requesterDid)) {
requesterDid = `${AID_PREFIX}${requesterDid}`
}
Expand Down
16 changes: 7 additions & 9 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
const { abi: libAbi } = require('./build/contracts/Library.json')
const { abi: proxyAbi } = require('./build/contracts/AFS.json')
const { LIBRARY_ADDRESS } = require('./constants')

const {
proxyExists,
getProxyAddress
} = require('./registry')
const { getProxyAddress } = require('./registry')

const {
hashDID,
Expand Down Expand Up @@ -119,11 +115,13 @@ async function hasPurchased(opts) {
}

const { purchaserDid, contentDid, keyringOpts } = opts
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)
let proxy
try {
proxy = await getProxyAddress(contentDid)
} catch (err) {
throw err
}
let purchaser = await getAddressFromDID(purchaserDid, keyringOpts)

if (!isAddress(purchaser)) {
Expand Down
16 changes: 7 additions & 9 deletions purchase.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const { abi: afsAbi } = require('./build/contracts/AFS.json')
const debug = require('debug')('ara-contracts:purchase')
const { getProxyAddress } = require('./registry')
const { randomBytes } = require('ara-crypto')
const { AID_PREFIX } = require('./constants')
const token = require('./token')

const {
proxyExists,
getProxyAddress
} = require('./registry')

const {
hasPurchased,
getLibrarySize,
Expand Down Expand Up @@ -87,11 +83,13 @@ async function purchase(opts) {
throw new Error('Identity has already purchased this')
}

if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
let proxy
try {
proxy = await getProxyAddress(contentDid)
} catch (err) {
throw err
}

const proxy = await getProxyAddress(contentDid)

let price = await call({
abi: afsAbi,
address: proxy,
Expand Down
19 changes: 8 additions & 11 deletions registry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { abi } = require('./build/contracts/Registry.json')
const debug = require('debug')('ara-contracts:registry')
const { parse, resolve } = require('path')
const { deprecate } = require('util')
const solc = require('solc')
const fs = require('fs')

Expand All @@ -26,15 +27,6 @@ const {
}
} = require('ara-util')

async function proxyExists(contentDid = '') {
try {
const address = await getProxyAddress(contentDid)
return !/^0x0+$/.test(address)
} catch (err) {
return false
}
}

/**
* Gets the proxy contract address for contentDid
* @param {String} contentDid //unhashed
Expand All @@ -48,18 +40,24 @@ async function getProxyAddress(contentDid = '') {

contentDid = normalize(contentDid)

let address
try {
return call({
address = await call({
abi,
address: REGISTRY_ADDRESS,
functionName: 'getProxyAddress',
arguments: [
ethify(contentDid)
]
})
if (!/^0x0+$/.test(address)) {
throw new Error('Content does not have a valid proxy.')
}
} catch (err) {
throw err
}

return address
}

async function getProxyVersion(contentDid = '') {
Expand Down Expand Up @@ -430,7 +428,6 @@ async function deployNewStandard(opts) {
}

module.exports = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we deprecate proxyExists? it looks like deprecate was required but not used

proxyExists,
deployProxy,
getStandard,
upgradeProxy,
Expand Down
26 changes: 1 addition & 25 deletions rewards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { abi: tokenAbi } = require('./build/contracts/AraToken.json')
const { abi: afsAbi } = require('./build/contracts/AFS.json')
const debug = require('debug')('ara-contracts:rewards')
const { getProxyAddress } = require('./registry')
const { info } = require('ara-console')
const token = require('./token')

Expand All @@ -10,11 +11,6 @@ const {
AID_PREFIX
} = require('./constants')

const {
proxyExists,
getProxyAddress
} = require('./registry')

const {
validate,
normalize,
Expand Down Expand Up @@ -105,10 +101,6 @@ async function submit(opts) {

let receipt
try {
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)

budget = budget.toString()
Expand Down Expand Up @@ -253,10 +245,6 @@ async function allocate(opts) {
debug(did, 'allocating rewards for job:', jobId)

try {
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)
const allocateTx = await tx.create({
account: acct,
Expand Down Expand Up @@ -333,10 +321,6 @@ async function redeem(opts) {

let balance = 0
try {
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)

const redeemTx = await tx.create({
Expand Down Expand Up @@ -395,10 +379,6 @@ async function getBudget(opts) {
contentDid = normalize(contentDid)

try {
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)
const budget = await call({
abi: afsAbi,
Expand Down Expand Up @@ -451,10 +431,6 @@ async function getRewardsBalance(opts) {
const { address } = await account.load({ did, password })

try {
if (!(await proxyExists(contentDid))) {
throw new Error('This content does not have a valid proxy contract')
}

const proxy = await getProxyAddress(contentDid)
const balance = await call({
abi: afsAbi,
Expand Down