UNPKG

4.12 kBJavaScriptView Raw
1'use strict'
2const CONFIG = require('./config');
3const TYPE = require('./type');
4const CODE = require('./code');
5
6const ABI = require('./core/abi');
7const Code = require('./model/code');
8const Method = require("./model/method");
9const Contract = require('./model/contract');
10const Request = require('./model/request');
11const Parameter = require('./model/parameter');
12const SignedTransaction = require('./model/signedTransaction');
13const SignedRequest = require('./model/signedRequest');
14const SignedData = require('./model/signedData');
15
16const ArithmeticOperator = require('./smartMethod/arithmeticOperator');
17const BasicOperator = require('./smartMethod/basicOperator');
18const CastOperator = require('./smartMethod/castOperator');
19const ChainOperator = require('./smartMethod/chainOperator');
20const ComparisonOperator = require('./smartMethod/comparisonOperator');
21const ReadOperator = require('./smartMethod/readOperator');
22const UtilOperator = require('./smartMethod/utilOperator');
23const WriteOperator = require('./smartMethod/writeOperator');
24const EthereumOperator = require('./smartMethod/ethereumOperator');
25
26const Factory = require('./rpc/factory');
27const Sender = require('./rpc/sender');
28const Node = require('./rpc/node');
29
30const Enc = require('./util/enc');
31const Clock = require('./util/clock');
32const Hasher = require('./util/hasher');
33const Signer = require('./util/signer');
34const Account = require('./util/account');
35const Math = require('./util/math');
36const Etc = require('./util/etc');
37const Common = require("./core/common");
38const {network} = require("locutus/php");
39
40module.exports = class Saseul {
41
42 /**
43 * Initiate Saseul instance
44 * @param option: {
45 * network_name: [String] SASEUL NETWORK (optional)
46 * system_nonce: [String] (optional)
47 * default_peers: [Array] (optional)
48 * genesis_address: [String] (optional)
49 * manager_addresses: [Array] (optional)
50 * abi: [Object] (optional)
51 * }
52 */
53 constructor(option = {
54 network_name: null,
55 system_nonce: null,
56 default_peers: [],
57 genesis_address: null,
58 manager_addresses: [],
59 abi: null
60 }) {
61 try {
62 if(!!option.abi && typeof option.abi !== 'object') throw 'abi must be an object.';
63 if(!!option.default_peers && !Array.isArray(option.default_peers)) throw 'default_peers must be an array.';
64 if(!!option.abi) this.Core.ABI = new ABI(option.abi);
65 if(!!option.network_name) this.CONFIG.NETWORK = option.network_name;
66 if(!!option.system_nonce) this.CONFIG._system_nonce = option.system_nonce;
67 if(!!option.genesis_address) this.CONFIG._genesis_address = option.genesis_address;
68 if(option.default_peers && option.default_peers?.length > 0) this.Rpc.Node = new Node(option.default_peers);
69 if(option.manager_addresses && option.manager_addresses?.length > 0) this.CONFIG._manager_addresses = option.manager_addresses;
70 } catch (e) {
71 throw e;
72 }
73 }
74
75 CONFIG = CONFIG;
76 TYPE = TYPE;
77 CODE = CODE;
78
79 Core = {
80 ABI: new ABI(),
81 Common: Common
82 }
83 Model = {
84 Code: Code,
85 Method: Method,
86 Contract: Contract,
87 Request: Request,
88 Parameter: Parameter,
89 SignedData: SignedData,
90 SignedRequest: SignedRequest,
91 SignedTransaction: SignedTransaction,
92 }
93 SmartMethod = {
94 ArithmeticOperator: ArithmeticOperator,
95 BasicOperator: BasicOperator,
96 CastOperator: CastOperator,
97 ChainOperator: ChainOperator,
98 ComparisonOperator: ComparisonOperator,
99 ReadOperator: ReadOperator,
100 UtilOperator: UtilOperator,
101 WriteOperator: WriteOperator,
102 EthereumOperator: EthereumOperator,
103 }
104 Rpc = {
105 Factory: Factory,
106 Sender: Sender,
107 Node: Node,
108 Code: Code,
109 }
110 Util = {
111 Enc: Enc,
112 Clock: Clock,
113 Hasher: Hasher,
114 Signer: Signer,
115 Account: Account,
116 Math: Math,
117 Etc: Etc,
118 }
119}
\No newline at end of file