Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
vdg authored and clbrge committed Nov 9, 2020
1 parent 13371d1 commit 7863c63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"dependencies": {
"elliptic": "^6.5.3",
"hex64": "^0.4.0",
"rouge-protocol-solidity": "0.20.0"
"rouge-protocol-solidity": "0.21.0"
},
"husky": {
"hooks": {
Expand Down
27 changes: 18 additions & 9 deletions src/rouge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RGEToken from 'rouge-protocol-solidity/build/contracts/RGETokenInterface.
import RougeFactory from 'rouge-protocol-solidity/build/contracts/RougeFactory.json'
import SimpleRougeCampaign from 'rouge-protocol-solidity/build/contracts/SimpleRougeCampaign.json'

import { RougeProtocolAddress, RougeAuthorization } from './constants'
import { NetworkName, RougeProtocolAddress, RougeAuthorization } from './constants'
import { universalAccount, universalScheme, sendTransaction, transact, successfulTransact } from './internalUtils'

import RougeUtils from './utils'
Expand Down Expand Up @@ -74,6 +74,14 @@ function RougeProtocol (web3, context = {}) {
// get RGEbalance () { return factory$RGEbalance() },
})

const status = () => Promise.all([
new Promise(resolve => resolve(web3.eth.net.getId().then(id => NetworkName[id]))),
RGE$address(),
factory$address(),
factory$version(),
factory$tare()
])

const control = async () => {
if ((await RGE$address()).toLowerCase() !== (await factory$rgeAddress()).toLowerCase()) {
throw new Error('RGE protocol not ready: rge address not set in factory')
Expand Down Expand Up @@ -139,21 +147,21 @@ function RougeProtocol (web3, context = {}) {
}
}

// const getCampaignList = async ({issuer}) => {
// // NewCampaign TODO add in protocol issuer + version protocol
// TODO add in protocol issuer + version protocol
const getIssuedCampaignList = async ({scheme, issuer}) => {
// TODO issuer // protocol version filter
// TODO add protocol version ?
const getIssuedCampaignList = async ({issuer, scheme}) => {
try {
const abiSignEvent = web3.eth.abi.encodeEventSignature(_AbiEvents.Issuance)
const encodedScheme = web3.utils.padRight(scheme, 64)
const logs = await web3.eth.getPastLogs({
fromBlock: 1, // 4056827, should be factory/version create block by default per network ?
topics: [abiSignEvent, encodedScheme]
topics: [abiSignEvent, null, issuer, scheme]
})
return logs.map(log => {
const tmp = _decodeLog('Issuance', log)
return { ...tmp, scheme: tmp.scheme.substring(0, 10), version: tmp.version.substring(0, 6) }
})
return Promise.resolve(logs.map(log => _decodeLog('Issuance', log)))
} catch (e) {
return Promise.reject(new Error(`[rouge.js] getIssuedCampaignList failed: ${e}`))
throw new Error(`[rouge.js] getIssuedCampaignList failed: ${e}`)
}
}

Expand Down Expand Up @@ -181,6 +189,7 @@ function RougeProtocol (web3, context = {}) {
get factory$ () { return factory$ },
get account$ () { return account$() },
campaign$,
status,
// verb => potential mutation, always return Promise, pipe always end
createCampaign,
// getCampaignList,
Expand Down
2 changes: 1 addition & 1 deletion test/campaign.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('RougeProtocol(web3).createCampaign()', () => {
})

describe('campaign.version()', () => {
const expected = `${major}.${minor}`
const expected = `0x${major.padStart(2, '0')}${minor.padStart(2, '0')}`
test(
`should return ${expected}`,
() => campaignPromise.then(
Expand Down

0 comments on commit 7863c63

Please sign in to comment.