-
Notifications
You must be signed in to change notification settings - Fork 17
/
uGenericScheme.ts
61 lines (55 loc) · 1.62 KB
/
uGenericScheme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Arc } from '../arc'
import { Proposal } from '../proposal'
import { Address } from '../types'
export interface IUGenericSchemeInfo {
id: string
contractToCall: Address
votingMachine: Address
}
export interface IUGenericScheme {
id: string
contractToCall: Address
callData: string
executed: boolean
returnValue: string
}
export interface IProposalCreateOptionsGS {
callData?: string
value?: number
}
export enum IProposalType {
GenericScheme = 'UGenericScheme'
}
export function createTransaction(options: any, context: Arc) {
if (!options.callData) {
throw new Error(`Missing argument "callData" for UGenericScheme in Proposal.create()`)
}
if (options.value === undefined) {
throw new Error(`Missing argument "value" for UGenericScheme in Proposal.create()`)
}
return async () => {
options.descriptionHash = await context.saveIPFSData(options)
const genericScheme = context.getContract(options.scheme)
const transaction = genericScheme.methods.proposeCall(
options.dao,
options.callData,
options.value,
options.descriptionHash
)
return transaction
}
}
/**
* map the transaction receipt of the createTransaction call to a nice result
* @param options the options passed to the createProposal call
* @param context an Arc instance
* @return [description]
*/
export function createTransactionMap(options: any, context: Arc) {
const eventName = 'NewCallProposal'
const map = async (receipt: any) => {
const proposalId = receipt.events[eventName].returnValues._proposalId
return new Proposal(proposalId, context)
}
return map
}