@com-chain/jsc3l 2.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +45 -0
- package/build/bcRead.d.ts +15 -0
- package/build/bcRead.js +123 -0
- package/build/bcRead.js.map +1 -0
- package/build/bcTransaction.d.ts +10 -0
- package/build/bcTransaction.js +135 -0
- package/build/bcTransaction.js.map +1 -0
- package/build/blockies.d.ts +1 -0
- package/build/blockies.js +91 -0
- package/build/blockies.js.map +1 -0
- package/build/config.d.ts +6 -0
- package/build/config.js +25 -0
- package/build/config.js.map +1 -0
- package/build/connection.d.ts +58 -0
- package/build/connection.js +204 -0
- package/build/connection.js.map +1 -0
- package/build/customization.d.ts +37 -0
- package/build/customization.js +129 -0
- package/build/customization.js.map +1 -0
- package/build/ethereum/cipher.d.ts +3 -0
- package/build/ethereum/cipher.js +94 -0
- package/build/ethereum/cipher.js.map +1 -0
- package/build/ethereum/ethFuncs.d.ts +12 -0
- package/build/ethereum/ethFuncs.js +70 -0
- package/build/ethereum/ethFuncs.js.map +1 -0
- package/build/ethereum/etherUnits.d.ts +5 -0
- package/build/ethereum/etherUnits.js +60 -0
- package/build/ethereum/etherUnits.js.map +1 -0
- package/build/ethereum/myetherwallet.d.ts +47 -0
- package/build/ethereum/myetherwallet.js +294 -0
- package/build/ethereum/myetherwallet.js.map +1 -0
- package/build/ethereum/uiFuncs.d.ts +3 -0
- package/build/ethereum/uiFuncs.js +51 -0
- package/build/ethereum/uiFuncs.js.map +1 -0
- package/build/index.d.ts +111 -0
- package/build/index.js +310 -0
- package/build/index.js.map +1 -0
- package/build/memo.d.ts +6 -0
- package/build/memo.js +24 -0
- package/build/memo.js.map +1 -0
- package/build/qr.d.ts +8 -0
- package/build/qr.js +35 -0
- package/build/qr.js.map +1 -0
- package/build/rest/ajaxReq.d.ts +31 -0
- package/build/rest/ajaxReq.js +127 -0
- package/build/rest/ajaxReq.js.map +1 -0
- package/build/rest/endpoint.d.ts +18 -0
- package/build/rest/endpoint.js +26 -0
- package/build/rest/endpoint.js.map +1 -0
- package/build/rest/http.d.ts +10 -0
- package/build/rest/http.js +60 -0
- package/build/rest/http.js.map +1 -0
- package/build/rest/serializer.d.ts +1 -0
- package/build/rest/serializer.js +94 -0
- package/build/rest/serializer.js.map +1 -0
- package/build/type.d.ts +24 -0
- package/build/type.js +9 -0
- package/build/type.js.map +1 -0
- package/build/wallet.d.ts +35 -0
- package/build/wallet.js +162 -0
- package/build/wallet.js.map +1 -0
- package/package.json +41 -0
- package/src/bcRead.ts +184 -0
- package/src/bcTransaction.ts +157 -0
- package/src/blockies.ts +113 -0
- package/src/config.ts +33 -0
- package/src/connection.ts +243 -0
- package/src/customization.ts +156 -0
- package/src/ethereum/cipher.ts +118 -0
- package/src/ethereum/ethFuncs.ts +73 -0
- package/src/ethereum/etherUnits.ts +66 -0
- package/src/ethereum/myetherwallet.ts +354 -0
- package/src/ethereum/uiFuncs.ts +55 -0
- package/src/index.ts +366 -0
- package/src/memo.ts +37 -0
- package/src/qr.ts +34 -0
- package/src/rest/ajaxReq.ts +160 -0
- package/src/rest/endpoint.ts +31 -0
- package/src/rest/http.ts +69 -0
- package/src/rest/serializer.ts +99 -0
- package/src/type.ts +37 -0
- package/src/wallet.ts +200 -0
- package/tsconfig.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# JSC3L
|
|
2
|
+
|
|
3
|
+
JavaScript Com-Chain Communication Library
|
|
4
|
+
|
|
5
|
+
## History
|
|
6
|
+
|
|
7
|
+
This lib was extracted from Biletujo project.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
This module provides a `Jsc3lAbstract` class that needs to be
|
|
12
|
+
subclassed to be used. This allows to inject different implementation
|
|
13
|
+
of core elements that may vary depending on where you are using the
|
|
14
|
+
JSC3L. There are only 2 elements to provide :
|
|
15
|
+
|
|
16
|
+
- httpRequest: a mean to make an http request
|
|
17
|
+
|
|
18
|
+
- persistentStorage: a storage that will persist between runs
|
|
19
|
+
|
|
20
|
+
These should follow precise behaviors and interfaces. You can find a
|
|
21
|
+
nice implementation for node and browsers in npm package
|
|
22
|
+
`jsc3l-browser`. Actually, you could only depend on this last package
|
|
23
|
+
if you are developping on a browser platform.
|
|
24
|
+
|
|
25
|
+
## Demo
|
|
26
|
+
|
|
27
|
+
An toy example is provided to show JSC3L usage in npm package `jsc3l-browser-test`.
|
|
28
|
+
You should have a glance at it.
|
|
29
|
+
|
|
30
|
+
## Developers
|
|
31
|
+
|
|
32
|
+
Package is using `npm` to track dependendies, so you can install them
|
|
33
|
+
with:
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
npm install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
As this package is written in `typescript`. You can transpile to
|
|
40
|
+
javascript and transpile on file change with:
|
|
41
|
+
|
|
42
|
+
```shell
|
|
43
|
+
## Compile and watch
|
|
44
|
+
npx tsc -w
|
|
45
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import AjaxReq from './rest/ajaxReq';
|
|
2
|
+
export default abstract class BcReadAbstract {
|
|
3
|
+
abstract ajaxReq: AjaxReq;
|
|
4
|
+
abstract contracts: string[];
|
|
5
|
+
getContractStatus(): Promise<unknown>;
|
|
6
|
+
getTaxAccount(): Promise<unknown>;
|
|
7
|
+
getHistoricalGlobalBalance(walletAddress: any, blockNb: any): Promise<string>;
|
|
8
|
+
getAmount(address: any, walletAddress: any): Promise<string>;
|
|
9
|
+
getAccInfo(address: any, walletAddress: any): Promise<number>;
|
|
10
|
+
getGlobInfo(address: any): Promise<unknown>;
|
|
11
|
+
getAmountAt(address: any, walletAddress: any, blockNb: any): Promise<string>;
|
|
12
|
+
getInfo(contract: any, address: any, walletAddress: any): Promise<number>;
|
|
13
|
+
getAmountForElement(contract: any, functionAddress: any, callerAddress: any, elementAddress: any): Promise<string>;
|
|
14
|
+
getElementInList(contract: any, mapFunctionAddress: any, amountFunctionAddress: any, callerAddress: any, index: any, list: any, indMin: any): any;
|
|
15
|
+
}
|
package/build/bcRead.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { getNakedAddress, padLeft, getDataObj } from './ethereum/ethFuncs';
|
|
3
|
+
function getNumber(data, ratio) {
|
|
4
|
+
const shortData = '0x' + data.slice(-12);
|
|
5
|
+
let a = parseInt(shortData, 16);
|
|
6
|
+
if (a > (34359738368 * 4096)) {
|
|
7
|
+
a -= 68719476736 * 4096;
|
|
8
|
+
}
|
|
9
|
+
return a / ratio;
|
|
10
|
+
}
|
|
11
|
+
export default class BcReadAbstract {
|
|
12
|
+
// Get Global status of the contract
|
|
13
|
+
async getContractStatus() { return this.getGlobInfo('0x8b3c7c69'); }
|
|
14
|
+
// Get Global infos: Tax destinary Account
|
|
15
|
+
async getTaxAccount() { return this.getGlobInfo('0x4f2eabe0'); }
|
|
16
|
+
// Get Historical infos infos: Global balance
|
|
17
|
+
async getHistoricalGlobalBalance(walletAddress, blockNb) {
|
|
18
|
+
return this.getAmountAt('0x70a08231', walletAddress, blockNb);
|
|
19
|
+
}
|
|
20
|
+
// //////////////////////////////////////////////////////////////////////////
|
|
21
|
+
// Generic read function
|
|
22
|
+
async getAmount(address, walletAddress) {
|
|
23
|
+
const userInfo = getDataObj(this.contracts[0], address, [getNakedAddress(walletAddress)]);
|
|
24
|
+
const data = await this.ajaxReq.getEthCall(userInfo);
|
|
25
|
+
return getNumber(data, 100.0).toString();
|
|
26
|
+
}
|
|
27
|
+
async getAccInfo(address, walletAddress) {
|
|
28
|
+
return this.getInfo(this.contracts[0], address, walletAddress);
|
|
29
|
+
}
|
|
30
|
+
getGlobInfo(address) {
|
|
31
|
+
const userInfo = getDataObj(this.contracts[0], address, []);
|
|
32
|
+
return this.ajaxReq.getEthCall(userInfo);
|
|
33
|
+
}
|
|
34
|
+
async getAmountAt(address, walletAddress, blockNb) {
|
|
35
|
+
const userInfo = getDataObj(this.contracts[0], address, [getNakedAddress(walletAddress)]);
|
|
36
|
+
const blockHex = '0x' + new BigNumber(blockNb).toString(16);
|
|
37
|
+
const data = await this.ajaxReq.getEthCallAt(userInfo, blockHex);
|
|
38
|
+
return getNumber(data, 100.0).toString();
|
|
39
|
+
}
|
|
40
|
+
async getInfo(contract, address, walletAddress) {
|
|
41
|
+
const userInfo = getDataObj(contract, address, [getNakedAddress(walletAddress)]);
|
|
42
|
+
const data = await this.ajaxReq.getEthCall(userInfo);
|
|
43
|
+
return getNumber(data, 1.0);
|
|
44
|
+
}
|
|
45
|
+
async getAmountForElement(contract, functionAddress, callerAddress, elementAddress) {
|
|
46
|
+
const userInfo = getDataObj(contract, functionAddress, [
|
|
47
|
+
getNakedAddress(callerAddress),
|
|
48
|
+
getNakedAddress(elementAddress)
|
|
49
|
+
]);
|
|
50
|
+
const data = await this.ajaxReq.getEthCall(userInfo);
|
|
51
|
+
return getNumber(data, 100.0).toString();
|
|
52
|
+
}
|
|
53
|
+
async getElementInList(contract, mapFunctionAddress, amountFunctionAddress, callerAddress, index, list, indMin) {
|
|
54
|
+
if (index < indMin)
|
|
55
|
+
return list;
|
|
56
|
+
const userInfo = getDataObj(contract, mapFunctionAddress, [
|
|
57
|
+
getNakedAddress(callerAddress),
|
|
58
|
+
padLeft(new BigNumber(index).toString(16), 64)
|
|
59
|
+
]);
|
|
60
|
+
const data = await this.ajaxReq.getEthCall(userInfo);
|
|
61
|
+
const amount = await this.getAmountForElement(contract, amountFunctionAddress, callerAddress, data);
|
|
62
|
+
const cleanedAdd = '0x' + data.substring(data.length - 40);
|
|
63
|
+
const element = { address: cleanedAdd, amount: amount };
|
|
64
|
+
list.unshift(element);
|
|
65
|
+
return this.getElementInList(contract, mapFunctionAddress, amountFunctionAddress, callerAddress, index - 1, list, indMin);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const fnHashes = [
|
|
69
|
+
{
|
|
70
|
+
fn: 'getAmount',
|
|
71
|
+
hashes: {
|
|
72
|
+
getGlobalBalance: '0x70a08231',
|
|
73
|
+
getNantBalance: '0xae261aba',
|
|
74
|
+
getCmBalance: '0xbbc72a17',
|
|
75
|
+
getCmLimitBelow: '0xcc885a65',
|
|
76
|
+
getCmLimitAbove: '0xae7143d6'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
fn: 'getAccInfo',
|
|
81
|
+
hashes: {
|
|
82
|
+
getAccountStatus: '0x61242bdd',
|
|
83
|
+
getAccountType: '0xba99af70',
|
|
84
|
+
getIsOwner: '0x2f54bf6e',
|
|
85
|
+
getTaxAmount: '0x98a9cfac',
|
|
86
|
+
getLegTaxAmount: '0x48455399',
|
|
87
|
+
getTotalAmount: '0x18160ddd'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
fnHashes.forEach(({ fn, hashes }) => {
|
|
92
|
+
for (const fnName in hashes) {
|
|
93
|
+
const fnHash = hashes[fnName];
|
|
94
|
+
BcReadAbstract.prototype[fnName] = function (walletAddress) {
|
|
95
|
+
return this[fn](fnHash, walletAddress);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// Handle lists
|
|
100
|
+
const ListFunction = {
|
|
101
|
+
Allowance: { count: 'aa7adb3d', map: 'b545b11f', amount: 'dd62ed3e' },
|
|
102
|
+
RequestToApprove: { count: 'debb9d28', map: '726d0a28', amount: '3537d3fa' },
|
|
103
|
+
PendingRequest: { count: '418d0fd4', map: '0becf93f', amount: '09a15e43' },
|
|
104
|
+
Delegation: { count: '58fb5218', map: 'ca40edf1', amount: '046d3307' },
|
|
105
|
+
MyDelegation: { count: '7737784d', map: '49bce08d', amount: 'f24111d2' },
|
|
106
|
+
AcceptedRequest: { count: '8d768f84', map: '59a1921a', amount: '958cde37' },
|
|
107
|
+
RejectedRequest: { count: '20cde8fa', map: '9aa9366e', amount: 'eac9dd4d' }
|
|
108
|
+
};
|
|
109
|
+
for (const key in ListFunction) {
|
|
110
|
+
const configList = ListFunction[key];
|
|
111
|
+
BcReadAbstract.prototype[`get${key}List`] =
|
|
112
|
+
async function (walletAddress, indMin, indMax) {
|
|
113
|
+
// Simple protection against ill inputs on indMin and indMax and to
|
|
114
|
+
// avoid unwanted infinite loops
|
|
115
|
+
indMax = indMax || 0;
|
|
116
|
+
indMin = indMin || 0;
|
|
117
|
+
const count = await this.getInfo(this.contracts[1], `0x${configList.count}`, walletAddress);
|
|
118
|
+
const list = [];
|
|
119
|
+
const index = Math.min(count - 1, indMax);
|
|
120
|
+
return this.getElementInList(this.contracts[1], `0x${configList.map}`, `0x${configList.amount}`, walletAddress, index, list, indMin);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=bcRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bcRead.js","sourceRoot":"","sources":["../src/bcRead.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAA;AAGpC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAG1E,SAAS,SAAS,CAAE,IAAI,EAAE,KAAK;IAC7B,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;IACxC,IAAI,CAAC,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAE/B,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE;QAC5B,CAAC,IAAI,WAAW,GAAG,IAAI,CAAA;KACxB;IAED,OAAO,CAAC,GAAG,KAAK,CAAA;AAClB,CAAC;AAGD,MAAM,CAAC,OAAO,OAAgB,cAAc;IAK1C,oCAAoC;IACpC,KAAK,CAAC,iBAAiB,KAAM,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA,CAAC,CAAC;IACpE,0CA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AC3C,mEAAmE;YACnE,gCAAgC;YAChC,MAAM,GAAG,MAAM,IAAI,CAAC,CAAA;YACpB,MAAM,GAAG,MAAM,IAAI,CAAC,CAAA;YACpB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAC9B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EACjB,KAAK,UAAU,CAAC,KAAK,EAAE,EACvB,aAAa,CAAC,CAAA;YAChB,MAAM,IAAI,GAAG,EAAE,CAAA;YACf,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;YACzC,OAAO,IAAI,CAAC,gBAAgB,CAC1B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EACjB,KAAK,UAAU,CAAC,GAAG,EAAE,EACrB,KAAK,UAAU,CAAC,MAAM,EAAE,EACxB,aAAa,EACb,KAAK,EACL,IAAI,EACJ,MAAM,CAAC,CAAA;QACX,CAAC,CAAA;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import AjaxReq from './rest/ajaxReq';
|
|
2
|
+
export default abstract class BcTransactionAbstract {
|
|
3
|
+
abstract ajaxReq: AjaxReq;
|
|
4
|
+
abstract contracts: string[];
|
|
5
|
+
getSplitting(nantVal: any, cmVal: any, cmMinusLim: any, amount: any): {
|
|
6
|
+
possible: boolean;
|
|
7
|
+
nant: number;
|
|
8
|
+
cm: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getNakedAddress, padLeft, encodeNumber } from './ethereum/ethFuncs';
|
|
2
|
+
import { generateTx } from './ethereum/uiFuncs';
|
|
3
|
+
function roundCent(strAmount) {
|
|
4
|
+
return Math.round(100 * parseFloat(strAmount));
|
|
5
|
+
}
|
|
6
|
+
function typeConv(label) {
|
|
7
|
+
if (label.endsWith('Address')) {
|
|
8
|
+
return (a) => padLeft(getNakedAddress(a), 64);
|
|
9
|
+
}
|
|
10
|
+
if (label.startsWith('limit') || label === 'amount') {
|
|
11
|
+
return (nb) => encodeNumber(roundCent(nb));
|
|
12
|
+
}
|
|
13
|
+
if (label.endsWith('Status') || label.endsWith('Type')) {
|
|
14
|
+
return (nb) => encodeNumber(nb);
|
|
15
|
+
}
|
|
16
|
+
if (label === 'status') {
|
|
17
|
+
return (nb) => (parseInt(nb, 10) === 0 ? 0 : 1);
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Unexpected label '${label}' in FnDefs.`);
|
|
20
|
+
}
|
|
21
|
+
export default class BcTransactionAbstract {
|
|
22
|
+
// //////////////////////////////////////////////////////////////////////////
|
|
23
|
+
// CM VS Nant Handling
|
|
24
|
+
getSplitting(nantVal, cmVal, cmMinusLim, amount) {
|
|
25
|
+
cmVal = parseFloat(cmVal);
|
|
26
|
+
nantVal = parseFloat(nantVal);
|
|
27
|
+
let nant = 0;
|
|
28
|
+
let cm = 0;
|
|
29
|
+
let res = parseFloat(amount);
|
|
30
|
+
if (cmVal > 0) {
|
|
31
|
+
if (cmVal >= res) {
|
|
32
|
+
cm = res;
|
|
33
|
+
res = 0;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
cm = cmVal;
|
|
37
|
+
res = res - cmVal;
|
|
38
|
+
cmVal = 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (nantVal > 0) {
|
|
42
|
+
if (nantVal >= res) {
|
|
43
|
+
nant = res;
|
|
44
|
+
res = 0;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
nant = nantVal;
|
|
48
|
+
res = res - nantVal;
|
|
49
|
+
// nantVal=0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (res > 0 && cmVal - parseFloat(cmMinusLim) >= res) {
|
|
53
|
+
cm = cm + res;
|
|
54
|
+
res = 0;
|
|
55
|
+
}
|
|
56
|
+
const possible = res === 0;
|
|
57
|
+
return { possible: possible, nant: nant, cm: cm };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
[
|
|
61
|
+
// First Contract
|
|
62
|
+
{
|
|
63
|
+
setAccountParam: '848b2592:accAddress accStatus accType limitPlus limitMinus',
|
|
64
|
+
pledgeAccount: '6c343eef:accAddress amount *',
|
|
65
|
+
setAllowance: 'd4e12f2e:spenderAddress amount',
|
|
66
|
+
setDelegation: '75741c79:spenderAddress limit',
|
|
67
|
+
setTaxAmount: 'f6f1897d:amount',
|
|
68
|
+
setTaxLegAmount: 'fafaf4c0:amount',
|
|
69
|
+
setTaxAccount: 'd0385b5e:accAddress',
|
|
70
|
+
setOwnerAccount: 'f2fde38b:accAddress',
|
|
71
|
+
setContractStatus: '0x88b8084f:status',
|
|
72
|
+
},
|
|
73
|
+
// Second Contract
|
|
74
|
+
{
|
|
75
|
+
transferNant: 'a5f7c148:toAddress amount *',
|
|
76
|
+
transferCM: '60ca9c4c:toAddress amount *',
|
|
77
|
+
transferOnBehalfNant: '1b6b1ee5:fromAddress toAddress amount D',
|
|
78
|
+
transferOnBehalfCM: '74c421fe:fromAddress toAddress amount D',
|
|
79
|
+
askTransferFrom: '58258353:fromAddress amount',
|
|
80
|
+
askTransferCMFrom: '2ef9ade2:fromAddress amount',
|
|
81
|
+
payRequestNant: '132019f4:toAddress amount *',
|
|
82
|
+
payRequestCM: '1415707c:toAddress amount *',
|
|
83
|
+
rejectRequest: 'af98f757:toAddress',
|
|
84
|
+
dismissAcceptedInfo: 'ccf93c7a:accAddress',
|
|
85
|
+
dismissRejectedInfo: '88759215:accAddress',
|
|
86
|
+
}
|
|
87
|
+
].forEach((contractFnDefs, contractNb) => {
|
|
88
|
+
for (const fnName in contractFnDefs) {
|
|
89
|
+
const [fnHash, argStringList] = contractFnDefs[fnName].split(':');
|
|
90
|
+
const argList = argStringList.split(' ');
|
|
91
|
+
let hasAdditionalPostData = false;
|
|
92
|
+
let hasDelegate = false;
|
|
93
|
+
if (argList.slice(-1)[0] === '*') {
|
|
94
|
+
hasAdditionalPostData = true;
|
|
95
|
+
argList.pop();
|
|
96
|
+
}
|
|
97
|
+
else if (argList.slice(-1)[0] === 'D') {
|
|
98
|
+
hasAdditionalPostData = true;
|
|
99
|
+
hasDelegate = true;
|
|
100
|
+
argList.pop();
|
|
101
|
+
}
|
|
102
|
+
// Build argument array function
|
|
103
|
+
const argFnList = argList.map((arg) => typeConv(arg));
|
|
104
|
+
const concatArgs = (args) => args.map((arg, idx) => argFnList[idx](arg)).join('');
|
|
105
|
+
BcTransactionAbstract.prototype[fnName] = async function (wallet, ...args) {
|
|
106
|
+
const addr = wallet.getAddressString();
|
|
107
|
+
const data = await this.ajaxReq.getTransactionData(addr);
|
|
108
|
+
// TODO: must test this
|
|
109
|
+
if (data.error) {
|
|
110
|
+
console.log(`Failed getTransactionData(${addr})`);
|
|
111
|
+
throw new Error(data.msg);
|
|
112
|
+
}
|
|
113
|
+
const additionalPostData = hasAdditionalPostData ? args.pop() : {};
|
|
114
|
+
if (hasDelegate) {
|
|
115
|
+
additionalPostData.delegate = wallet.getAddressString();
|
|
116
|
+
}
|
|
117
|
+
const rawTx = generateTx({
|
|
118
|
+
gasLimit: 500000,
|
|
119
|
+
data: fnHash + concatArgs(args),
|
|
120
|
+
to: this.contracts[contractNb],
|
|
121
|
+
unit: 'ether',
|
|
122
|
+
value: 0,
|
|
123
|
+
nonce: 1,
|
|
124
|
+
gasPrice: null,
|
|
125
|
+
donate: false,
|
|
126
|
+
from: addr,
|
|
127
|
+
key: wallet.getPrivateKeyString()
|
|
128
|
+
}, data);
|
|
129
|
+
if (rawTx.isError)
|
|
130
|
+
return rawTx;
|
|
131
|
+
return this.ajaxReq.sendTx(rawTx.signedTx, additionalPostData);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=bcTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bcTransaction.js","sourceRoot":"","sources":["../src/bcTransaction.ts"],"names":[],"mappings":"AACA,OAA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ACR,IAAI,KAAK,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAA;YAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAA;QAChE,CAAC,CAAA;KACF;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (opts: any): HTMLCanvasElement;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Adapted from
|
|
2
|
+
// https://github.com/alexvandesande/blockies/blob/master/blockies.js
|
|
3
|
+
// updated tayvano 3.9.16
|
|
4
|
+
// The random number is a js implementation of the Xorshift PRNG
|
|
5
|
+
const randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
|
|
6
|
+
function seedrand(seed) {
|
|
7
|
+
for (let i = 0; i < randseed.length; i++) {
|
|
8
|
+
randseed[i] = 0;
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0; i < seed.length; i++) {
|
|
11
|
+
randseed[i % 4] = ((randseed[i % 4] << 5) - randseed[i % 4]) +
|
|
12
|
+
seed.charCodeAt(i);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rand() {
|
|
16
|
+
// based on Java's String.hashCode(), expanded to 4 32bit values
|
|
17
|
+
const t = randseed[0] ^ (randseed[0] << 11);
|
|
18
|
+
randseed[0] = randseed[1];
|
|
19
|
+
randseed[1] = randseed[2];
|
|
20
|
+
randseed[2] = randseed[3];
|
|
21
|
+
randseed[3] = (randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8));
|
|
22
|
+
return (randseed[3] >>> 0) / ((1 << 31) >>> 0);
|
|
23
|
+
}
|
|
24
|
+
function createColor() {
|
|
25
|
+
// saturation is the whole color spectrum
|
|
26
|
+
const h = Math.floor(rand() * 360);
|
|
27
|
+
// saturation goes from 40 to 100, it avoids greyish colors
|
|
28
|
+
const s = ((rand() * 60) + 40) + '%';
|
|
29
|
+
// lightness can be anything from 0 to 100, but probabilities are a
|
|
30
|
+
// bell curve around 50%
|
|
31
|
+
const l = ((rand() + rand() + rand() + rand()) * 25) + '%';
|
|
32
|
+
const color = 'hsl(' + h + ',' + s + ',' + l + ')';
|
|
33
|
+
return color;
|
|
34
|
+
}
|
|
35
|
+
function createImageData(size) {
|
|
36
|
+
const width = size; // Only support square icons for now
|
|
37
|
+
const height = size;
|
|
38
|
+
const dataWidth = Math.ceil(width / 2);
|
|
39
|
+
const mirrorWidth = width - dataWidth;
|
|
40
|
+
const data = [];
|
|
41
|
+
for (let y = 0; y < height; y++) {
|
|
42
|
+
let row = [];
|
|
43
|
+
for (let x = 0; x < dataWidth; x++) {
|
|
44
|
+
// this makes foreground and background color to have a 43%
|
|
45
|
+
// (1/2.3) probability spot color has 13% chance
|
|
46
|
+
row[x] = Math.floor(rand() * 2.3);
|
|
47
|
+
}
|
|
48
|
+
const r = row.slice(0, mirrorWidth);
|
|
49
|
+
r.reverse();
|
|
50
|
+
row = row.concat(r);
|
|
51
|
+
for (let i = 0; i < row.length; i++) {
|
|
52
|
+
data.push(row[i]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
function createCanvas(imageData, color, scale, bgcolor, spotcolor) {
|
|
58
|
+
const c = document.createElement('canvas');
|
|
59
|
+
const width = Math.sqrt(imageData.length);
|
|
60
|
+
c.width = c.height = width * scale;
|
|
61
|
+
const cc = c.getContext('2d');
|
|
62
|
+
cc.fillStyle = bgcolor;
|
|
63
|
+
cc.fillRect(0, 0, c.width, c.height);
|
|
64
|
+
cc.fillStyle = color;
|
|
65
|
+
for (let i = 0; i < imageData.length; i++) {
|
|
66
|
+
const row = Math.floor(i / width);
|
|
67
|
+
const col = i % width;
|
|
68
|
+
// if data is 2, choose spot color, if 1 choose foreground
|
|
69
|
+
cc.fillStyle = (imageData[i] === 1) ? color : spotcolor;
|
|
70
|
+
// if data is 0, leave the background
|
|
71
|
+
if (imageData[i]) {
|
|
72
|
+
cc.fillRect(col * scale, row * scale, scale, scale);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return c;
|
|
76
|
+
}
|
|
77
|
+
export default function (opts) {
|
|
78
|
+
opts = opts || {};
|
|
79
|
+
const size = opts.size || 8;
|
|
80
|
+
const scale = opts.scale || 4;
|
|
81
|
+
const seed = opts.seed || Math.floor((Math.random() *
|
|
82
|
+
Math.pow(10, 16))).toString(16);
|
|
83
|
+
seedrand(seed);
|
|
84
|
+
const color = opts.color || createColor();
|
|
85
|
+
const bgcolor = opts.bgcolor || createColor();
|
|
86
|
+
const spotcolor = opts.spotcolor || createColor();
|
|
87
|
+
const imageData = createImageData(size);
|
|
88
|
+
const canvas = createCanvas(imageData, color, scale, bgcolor, spotcolor);
|
|
89
|
+
return canvas;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=blockies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockies.js","sourceRoot":"","sources":["../src/blockies.ts"],"names":[],"mappings":"AACA,eAAe;AACf,qEAAqE;AACrE,yBAAyB;AAEzB,gEAAgE;AAChE,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA,CAAC,uCAAuC;AAErE,SAAS,QAAQ,CAAE,IAAI;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;KAChB;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1D,IAAI,CAA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,IAAI,CAAC,MAAM,EAAE;QACjD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAEjC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAEd,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,WAAW,EAAE,CAAA;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,WAAW,EAAE,CAAA;IAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,WAAW,EAAE,CAAA;IACjD,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IAExE,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const confEndPointsOur: string[];
|
|
2
|
+
export declare const confEndPointsOther: string[];
|
|
3
|
+
export declare const configRepo = "/ipns/QmaAAZor2uLKnrzGCwyXTSwogJqmPjJgvpYgpmtz5XcSmR/configs";
|
|
4
|
+
export declare const nodesRepo = "/ipns/QmcRWARTpuEf9E87cdA4FfjBkv7rKTJyfvsLFTzXsGATbL";
|
|
5
|
+
export declare const custoRepo = "/ipns/QmaAAZor2uLKnrzGCwyXTSwogJqmPjJgvpYgpmtz5XcSmR/resources/";
|
|
6
|
+
export declare const ping: string;
|
package/build/config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const confEndPointsOur = [
|
|
2
|
+
'https://node-001.cchosting.org',
|
|
3
|
+
'https://node-002.cchosting.org',
|
|
4
|
+
'https://node-003.cchosting.org',
|
|
5
|
+
'https://node-004.cchosting.org',
|
|
6
|
+
'https://node-cc-001.cchosting.org/',
|
|
7
|
+
'https://api.monnaie-leman.org'
|
|
8
|
+
];
|
|
9
|
+
export const confEndPointsOther = [
|
|
10
|
+
'https://ipfs.io',
|
|
11
|
+
'https://ipfs.infura.io',
|
|
12
|
+
'https://ipfs.jes.xxx',
|
|
13
|
+
'https://siderus.io',
|
|
14
|
+
'https://hardbin.com',
|
|
15
|
+
'https://ipfs.infura.io',
|
|
16
|
+
'https://xmine128.tk'
|
|
17
|
+
];
|
|
18
|
+
// IPNS of the list of available ComChain currency configs
|
|
19
|
+
export const configRepo = '/ipns/QmaAAZor2uLKnrzGCwyXTSwogJqmPjJgvpYgpmtz5XcSmR/configs';
|
|
20
|
+
// IPNS of the list of available ComChain end-points
|
|
21
|
+
export const nodesRepo = '/ipns/QmcRWARTpuEf9E87cdA4FfjBkv7rKTJyfvsLFTzXsGATbL';
|
|
22
|
+
// IPNS of the configuration for the different currencies
|
|
23
|
+
export const custoRepo = '/ipns/QmaAAZor2uLKnrzGCwyXTSwogJqmPjJgvpYgpmtz5XcSmR/resources/';
|
|
24
|
+
export const ping = configRepo + '/ping.json';
|
|
25
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gCAAgC;IAChC,gCAAgC;IAChC,gCAAgC;IAChC,gCAAgC;IAChC,oCAAoC;IACpC,+BAA+B;CAChC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,iBAAiB;IACjB,wBAAwB;IACxB,sBAAsB;IACtB,oBAAoB;IACpB,qBAAqB;IACrB,wBAAwB;IACxB,qBAAqB;CACtB,CAAA;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,UAAU,GACrB,8DAA8D,CAAA;AAEhE,oDAAoD;AACpD,MAAM,CAAC,MAAM,SAAS,GACpB,sDAAsD,CAAA;AAExD,yDAAyD;AACzD,MAAM,CAAC,MAAM,SAAS,GACpB,iEAAiE,CAAA;AAEnE,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import HttpAbstract from './rest/http';
|
|
2
|
+
import * as t from './type';
|
|
3
|
+
declare abstract class ConnectionAbstract {
|
|
4
|
+
protected abstract http: HttpAbstract;
|
|
5
|
+
lookupAvailableComChainRepo(storedEndPointsSuggestion?: string[]): Promise<any>;
|
|
6
|
+
acquireEndPoint(repo: string): Promise<false | {
|
|
7
|
+
apiNodes: any;
|
|
8
|
+
endpoint: string | boolean;
|
|
9
|
+
}>;
|
|
10
|
+
getCCEndPointList(repo: string): Promise<any>;
|
|
11
|
+
selectEndPoint(nodes: string[]): Promise<string | false>;
|
|
12
|
+
testNode(apiAddress: any): Promise<any>;
|
|
13
|
+
checkRepo(repoList: any): Promise<any>;
|
|
14
|
+
testApi(apiAddress: any): Promise<any>;
|
|
15
|
+
testDbApi(apiAddress: any): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the configuration for the given currency
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
getConfJSON(repo: any, currencyName: any): Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manages Persistent Store to keep list of nodes and avoid IPFS lookup
|
|
24
|
+
* when possible.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export default abstract class ConnectionMgrAbstract extends ConnectionAbstract {
|
|
28
|
+
protected abstract persistentStore: t.IPersistentStore;
|
|
29
|
+
repo: string;
|
|
30
|
+
conf: any;
|
|
31
|
+
endpoint: string;
|
|
32
|
+
/**
|
|
33
|
+
* This lookup will store result in memory for speeding other methods.
|
|
34
|
+
*/
|
|
35
|
+
lookupAvailableComChainRepo(storedEndPointsSuggestion?: string[]): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* This lookup will store result in memory for speeding other methods.
|
|
38
|
+
* and saves the result in persistentStore for faster calls.
|
|
39
|
+
*/
|
|
40
|
+
acquireEndPoint(repo?: string): Promise<{
|
|
41
|
+
apiNodes: any;
|
|
42
|
+
endpoint: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* This lookup will store result in memory for speeding other methods.
|
|
46
|
+
* and saves the result in persistentStore for faster calls.
|
|
47
|
+
* - If argument `repo` is not provided, it'll use the last one in memory
|
|
48
|
+
* leaved by a previous call of `lookupAvailableComChainRepo()`.
|
|
49
|
+
* - If no previous call was made, it'll do one.
|
|
50
|
+
*/
|
|
51
|
+
getConfJSON(currencyName: string, repo?: string): Promise<any>;
|
|
52
|
+
/**
|
|
53
|
+
* Return conf stored in memory or persistent storage (need to
|
|
54
|
+
* be not async).
|
|
55
|
+
*/
|
|
56
|
+
getLocalConfJSON(): any;
|
|
57
|
+
}
|
|
58
|
+
export {};
|