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

Commit

Permalink
correctly decode Isuance log
Browse files Browse the repository at this point in the history
  • Loading branch information
vdg committed Feb 13, 2020
1 parent c09c4e1 commit d4bbd05
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ticket"
],
"authors": [
"Christophe Le Bars <clbg@rouge.network>",
"Christophe Le Bars <clb@rouge.network>",
"Valentin D. Guillois <[email protected]>"
],
"license": "AGPL-3.0-only",
Expand Down
14 changes: 12 additions & 2 deletions src/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ export default function Campaign (web3, address, { context, _decodeLog }) {
const tare = async () => instance.methods.tare().call()

// TODO cache information from getInfo
const info = async () => instance.methods.getInfo().call()
const infoRaw = async () => instance.methods.getInfo().call()
const issuer = async () => instance.methods.issuer().call()
const scheme = async () => instance.methods.scheme().call()
const expiration = async () => instance.methods.campaignExpiration().call()
const name = async () => instance.methods.name().call()

const info = async () => {
const data = await infoRaw()
return {
issuer: web3.utils.toChecksumAddress(data.slice(0, 42)),
scheme: '0x' + data.slice(42, 50),
expiration: web3.utils.hexToNumber('0x' + data.slice(50, 114)),
name: web3.utils.hexToAscii('0x' + data.slice(114))
}
}

const state = async () => instance.methods.getState().call()
const isIssued = async () => instance.methods.campaignIssued().call()
const issuance = async () => instance.methods.issuance().call()
Expand Down Expand Up @@ -113,7 +123,7 @@ export default function Campaign (web3, address, { context, _decodeLog }) {

const receipt = await _transact(method, address)
// const Issuance = _decodeLog('Issuance', receipt.logs[0])
// console.log("Issuance", receipt)
console.log('receipt', receipt)

return receipt
} catch (e) {
Expand Down
36 changes: 22 additions & 14 deletions src/rouge.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ function RougeProtocol (web3, context = {}) {
return acc
}, _AbiEvents)

const _decodeLog = (name, log) => web3.eth.abi.decodeLog(_AbiEvents[name].inputs, log.data, log.topics.slice(1))
const _decodeLog = (name, log) => ({
_event: name,
_address: log.address,
_log: log,
...web3.eth.abi.decodeLog(_AbiEvents[name].inputs, log.data, log.topics.slice(1))
})

const account$ = () => Object.freeze({
get address () { return context.as.address }
Expand Down Expand Up @@ -132,23 +137,25 @@ function RougeProtocol (web3, context = {}) {
}
}

const getCampaignList = async ({scheme, issuer}) => {
// const getCampaignList = async ({issuer}) => {
// // NewCampaign TODO add in protocol issuer + version protocol

// event Issuance(bytes4 indexed scheme, string name, uint campaignExpiration);
// TODO add in protocol issuer + version protocol
const getIssuedCampaignList = async ({scheme, issuer}) => {
try {
// const logs = await web3.eth.getPastLogs({
// address: factoryAddress,
// // event NewCampaign(address indexed issuer, address indexed campaign, uint32 issuance)
// topics: ['0x798fca4db5588d669d44c689c1949dc5566b003ef1d73792336bb11e46143085']
// })
// scheme should be in topics.
const abiSignEvent = web3.eth.abi.encodeEventSignature(_AbiEvents['Issuance'])
const encodedScheme = web3.utils.padRight(scheme, 64)
console.log('xxx', abiSignEvent, encodedScheme)
const logs = await web3.eth.getPastLogs({
fromBlock: 4056827, // should be factory/version create block by default
// address: factoryAddress,
// event Issuance(bytes4 scheme, string name, uint campaignExpiration) => add issuer + version
topics: ['0x61d7bd1b44357bca3ed4bd238fec71f1710af7c589ab829be7f3be96caa6c5eb']
// fromBlock: 4056827, // should be factory/version create block by default
topics: [abiSignEvent, encodedScheme]
})
return Promise.resolve(logs.map(log => log.address))

return Promise.resolve(logs.map(log => _decodeLog('Issuance', log)))
} catch (e) {
return Promise.reject(new Error(`[rouge.js] getCampaignList failed: ${e}`))
return Promise.reject(new Error(`[rouge.js] getIssuedCampaignList failed: ${e}`))
}
}

Expand Down Expand Up @@ -178,7 +185,8 @@ function RougeProtocol (web3, context = {}) {
campaign$,
// verb => potential mutation, always return Promise, pipe always end
createCampaign,
getCampaignList,
// getCampaignList,
getIssuedCampaignList,
sendFinney
}

Expand Down

0 comments on commit d4bbd05

Please sign in to comment.