/
contract.ts
45 lines (42 loc) · 1.46 KB
/
contract.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
import { ContractConfig } from "embark-core";
import { Logger } from 'embark-logger';
import { sha3, Serialize } from "embark-utils";
import { AbiItem } from "web3-utils";
@Serialize.Serializable
export default class Contract {
@Serialize.Ignore
private logger: Logger;
public abiDefinition?: AbiItem[];
public deployedAddress?: string;
public className: string = "";
public address?: string;
public args?: any[] = [];
public instanceOf?: string;
public gas?: number;
public gasPrice?: number;
public silent?: boolean = false;
public track?: boolean = true;
public deploy?: boolean = true;
public realRuntimeBytecode: string = "";
public realArgs: any[] = [];
constructor(logger: Logger, contractConfig: ContractConfig = {}) {
Object.assign(this, contractConfig);
this.logger = logger;
}
/**
* Calculates a hash from runtime bytecode, classname, and deploy arguments.
* Used for uniquely identifying a contract, ie in chains.json.
*/
get hash() {
return sha3(this.realRuntimeBytecode + this.className + (this.realArgs || this.args).join(","));
}
/**
* Logs a message to the console. Logs with loglevel trace if contract has it's silent
* property set (in the config or internally, ie ENS contracts). Otherwise, logs with
* info log level.
* @param {string} message message to log to the console
*/
public log(message: string) {
this.silent ? this.logger.trace(message) : this.logger.info(message);
}
}