@com-chain/jsc3l 2.0.1-rc.0 → 2.0.1-rc.10
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/build/bcRead.d.ts +8 -9
- package/build/bcRead.js +93 -35
- package/build/bcRead.js.map +1 -1
- package/build/bcTransaction.d.ts +2 -1
- package/build/bcTransaction.js +55 -76
- package/build/bcTransaction.js.map +1 -1
- package/build/config/transactions.d.ts +44 -0
- package/build/config/transactions.js +29 -0
- package/build/config/transactions.js.map +1 -0
- package/build/connection.js +14 -8
- package/build/connection.js.map +1 -1
- package/build/customization.js +11 -2
- package/build/customization.js.map +1 -1
- package/build/ethereum/ethFuncs.js +1 -1
- package/build/ethereum/ethFuncs.js.map +1 -1
- package/build/ethereum/etherUnits.js +5 -5
- package/build/ethereum/etherUnits.js.map +1 -1
- package/build/ethereum/uiFuncs.d.ts +1 -3
- package/build/ethereum/uiFuncs.js +13 -23
- package/build/ethereum/uiFuncs.js.map +1 -1
- package/build/index.d.ts +10 -6
- package/build/index.js +35 -21
- package/build/index.js.map +1 -1
- package/build/qr.d.ts +31 -6
- package/build/qr.js +32 -12
- package/build/qr.js.map +1 -1
- package/build/rest/ajaxReq.d.ts +2 -10
- package/build/rest/ajaxReq.js +10 -32
- package/build/rest/ajaxReq.js.map +1 -1
- package/build/type.d.ts +4 -4
- package/build/wallet.d.ts +7 -9
- package/build/wallet.js +31 -39
- package/build/wallet.js.map +1 -1
- package/package.json +3 -1
- package/src/bcRead.ts +108 -49
- package/src/bcTransaction.ts +58 -77
- package/src/config/transactions.ts +30 -0
- package/src/connection.ts +15 -7
- package/src/customization.ts +17 -2
- package/src/ethereum/ethFuncs.ts +1 -1
- package/src/ethereum/etherUnits.ts +5 -5
- package/src/ethereum/uiFuncs.ts +16 -25
- package/src/index.ts +50 -28
- package/src/qr.ts +86 -12
- package/src/rest/ajaxReq.ts +10 -39
- package/src/wallet.ts +40 -50
package/build/type.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const httpMethods: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"];
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type httpMethod = typeof httpMethods[number];
|
|
3
|
+
export type coreHttpOpts = {
|
|
4
4
|
protocol: string;
|
|
5
5
|
host: string;
|
|
6
6
|
path: string;
|
|
@@ -10,13 +10,13 @@ export declare type coreHttpOpts = {
|
|
|
10
10
|
data?: any;
|
|
11
11
|
timeout?: number;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type HttpRequest = (opts: coreHttpOpts) => Object;
|
|
14
14
|
export interface IPersistentStore {
|
|
15
15
|
get(key: string, defaultValue?: string): string;
|
|
16
16
|
set(key: string, value: string): void;
|
|
17
17
|
del(key: string): void;
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export type UrlParts = {
|
|
20
20
|
protocol: string;
|
|
21
21
|
host: string;
|
|
22
22
|
port: number;
|
package/build/wallet.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import AjaxReq from './rest/ajaxReq';
|
|
2
|
+
import { SignedQR } from './qr';
|
|
2
3
|
import Wallet from './ethereum/myetherwallet';
|
|
3
4
|
export default abstract class MessagingWalletAbstract extends Wallet {
|
|
4
5
|
abstract ajaxReq: AjaxReq;
|
|
@@ -10,7 +11,7 @@ export default abstract class MessagingWalletAbstract extends Wallet {
|
|
|
10
11
|
};
|
|
11
12
|
static createWallet(this: {
|
|
12
13
|
new (): MessagingWalletAbstract;
|
|
13
|
-
}): Promise<
|
|
14
|
+
}): Promise<MessagingWalletAbstract>;
|
|
14
15
|
private publishMessageKey;
|
|
15
16
|
publishReqMessages(addTo: any, message: any): Promise<any>;
|
|
16
17
|
ensureWalletMessageKey(): Promise<"REPLACED_WITH_REMOTE" | "CREATED_NEW">;
|
|
@@ -21,15 +22,12 @@ export default abstract class MessagingWalletAbstract extends Wallet {
|
|
|
21
22
|
encryptWallet(password: any): {
|
|
22
23
|
[k: string]: any;
|
|
23
24
|
};
|
|
24
|
-
enrollAddress(
|
|
25
|
+
enrollAddress(id: any, token: any): any;
|
|
25
26
|
requestUnlock(): any;
|
|
26
27
|
static getWalletFromPrivKeyFile(jsonStr: any, password: any): Wallet;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
makeSignedQR(obj: any): {
|
|
32
|
-
signature: any;
|
|
33
|
-
qrContent: string;
|
|
28
|
+
makeSignedQRContent(obj: any, pubKey: string | null): SignedQR;
|
|
29
|
+
makeSignedQRFragments(obj: any, fragmentCount: number, pubKey: string | null): {
|
|
30
|
+
full: string;
|
|
34
31
|
};
|
|
32
|
+
checkSignedQRFromString(qrString: string): true | "InvalidFormat" | "InvalidSignature" | "NotForYou" | "Expired";
|
|
35
33
|
}
|
package/build/wallet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { checkSignedQR, makeSignedQRContent, makeSignedQRFragments } from './qr';
|
|
2
2
|
import { shortenAddress, cipherMsg, decipherMsg } from './ethereum/cipher';
|
|
3
3
|
import Wallet from './ethereum/myetherwallet';
|
|
4
4
|
export default class MessagingWalletAbstract extends Wallet {
|
|
@@ -8,7 +8,8 @@ export default class MessagingWalletAbstract extends Wallet {
|
|
|
8
8
|
}
|
|
9
9
|
static async createWallet() {
|
|
10
10
|
const wallet = new this();
|
|
11
|
-
|
|
11
|
+
await wallet.ensureWalletMessageKey();
|
|
12
|
+
return wallet;
|
|
12
13
|
}
|
|
13
14
|
publishMessageKey() {
|
|
14
15
|
const dataStr = JSON.stringify({
|
|
@@ -34,7 +35,7 @@ export default class MessagingWalletAbstract extends Wallet {
|
|
|
34
35
|
async ensureWalletMessageKey() {
|
|
35
36
|
const remoteKey = await this.ajaxReq.getMessageKey(this.getAddressString(), true);
|
|
36
37
|
const walletMessageKey = this === null || this === void 0 ? void 0 : this.message_key;
|
|
37
|
-
if (remoteKey.public_message_key !== undefined) {
|
|
38
|
+
if (typeof remoteKey.public_message_key !== 'undefined') {
|
|
38
39
|
this.message_key = {
|
|
39
40
|
pub: remoteKey.public_message_key,
|
|
40
41
|
priv: remoteKey.private_message_key,
|
|
@@ -78,7 +79,7 @@ export default class MessagingWalletAbstract extends Wallet {
|
|
|
78
79
|
const newKey = Wallet.generate(false);
|
|
79
80
|
const mPub = newKey.getPublicKeyString();
|
|
80
81
|
const mPriv = newKey.getPrivateKeyString();
|
|
81
|
-
return { pub: mPub, priv: cipherMsg(this.
|
|
82
|
+
return { pub: mPub, priv: cipherMsg(this.getPublicKeyString(), mPriv) };
|
|
82
83
|
}
|
|
83
84
|
messageKeysFromCrypted(cipheredKey) {
|
|
84
85
|
// XXXvlab: here we are converting to hex and de-converting in decipherMsg...
|
|
@@ -98,8 +99,14 @@ export default class MessagingWalletAbstract extends Wallet {
|
|
|
98
99
|
message_key: this.message_key
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
|
-
enrollAddress(
|
|
102
|
-
return this.ajaxReq.
|
|
102
|
+
enrollAddress(id, token) {
|
|
103
|
+
return this.ajaxReq.enrollPost({
|
|
104
|
+
id,
|
|
105
|
+
token,
|
|
106
|
+
currency: this.currencyName,
|
|
107
|
+
// XXXvlab: Yes, typo is intentional here (in PHP API):
|
|
108
|
+
adresse: this.getAddressString(),
|
|
109
|
+
});
|
|
103
110
|
}
|
|
104
111
|
requestUnlock() {
|
|
105
112
|
return this.ajaxReq.requestUnlock(this.getAddressString(), this.unlockUrl);
|
|
@@ -123,40 +130,25 @@ export default class MessagingWalletAbstract extends Wallet {
|
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
//
|
|
126
|
-
// QR
|
|
133
|
+
// QR Code helpers
|
|
127
134
|
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return
|
|
145
|
-
signature,
|
|
146
|
-
qrContent: JSON.stringify({
|
|
147
|
-
data: objContent,
|
|
148
|
-
signature: {
|
|
149
|
-
v: signature.v,
|
|
150
|
-
r: '0x' + signature.r.toString('hex'),
|
|
151
|
-
s: '0x' + signature.s.toString('hex')
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
};
|
|
135
|
+
makeSignedQRContent(obj, pubKey) {
|
|
136
|
+
return makeSignedQRContent(Object.assign(Object.assign({ server: this.currencyName, address: this.getAddressString() }, obj), pubKey && {
|
|
137
|
+
message_key: cipherMsg(pubKey, this.messageKeysFromWallet())
|
|
138
|
+
}), this.privKey);
|
|
139
|
+
}
|
|
140
|
+
makeSignedQRFragments(obj, fragmentCount, pubKey) {
|
|
141
|
+
return makeSignedQRFragments(this.makeSignedQRContent(obj, pubKey), fragmentCount);
|
|
142
|
+
}
|
|
143
|
+
checkSignedQRFromString(qrString) {
|
|
144
|
+
let qrContent;
|
|
145
|
+
try {
|
|
146
|
+
qrContent = JSON.parse(qrString);
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
return 'InvalidFormat';
|
|
150
|
+
}
|
|
151
|
+
return checkSignedQR(qrContent, this.getAddressString());
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
|
-
// // TODO: What to do with this validateEnrollment
|
|
158
|
-
// public static validateEnrollment (codeId, signature) {
|
|
159
|
-
// return this.ajaxReq.validateEnrollmentLetter(
|
|
160
|
-
// codeId, this.currencyName, signature)
|
|
161
|
-
// }
|
|
162
154
|
//# sourceMappingURL=wallet.js.map
|
package/build/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet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"@com-chain/jsc3l",
|
|
3
|
-
"version": "2.0.1-rc.
|
|
3
|
+
"version": "2.0.1-rc.10",
|
|
4
4
|
"description": "JavaScript Com-Chain Communication Library",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/com-chain/JSC3L#readme",
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@0k.io/prettier": "^0.0.1",
|
|
27
28
|
"@types/node": "^16.10.3",
|
|
28
29
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
29
30
|
"@typescript-eslint/parser": "^4.33.0",
|
|
30
31
|
"eslint": "^7.29.0",
|
|
32
|
+
"eslint-config-standard": "^16.0.3",
|
|
31
33
|
"typescript": "^4.4.3"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
package/src/bcRead.ts
CHANGED
|
@@ -4,15 +4,68 @@ import AjaxReq from './rest/ajaxReq'
|
|
|
4
4
|
import { getNakedAddress, padLeft, getDataObj } from './ethereum/ethFuncs'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
function getNumber (data, ratio) {
|
|
8
|
-
const shortData = '0x' + data.slice(-12)
|
|
9
|
-
let a = parseInt(shortData, 16)
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
function decodeData (abiType: string, data: string): any {
|
|
9
|
+
if (data.startsWith('0x')) {
|
|
10
|
+
data = data.slice(2)
|
|
11
|
+
}
|
|
12
|
+
if (data.length === 0) {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
let dataBuffer: Buffer
|
|
16
|
+
try {
|
|
17
|
+
dataBuffer = Buffer.from(data, 'hex')
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'Invalid data provided: not an hex string')
|
|
21
|
+
}
|
|
22
|
+
if (dataBuffer.length % 32 !== 0) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Invalid data provided: data length is not a multiple of 32')
|
|
25
|
+
}
|
|
26
|
+
const uintData = dataBuffer.readUIntBE(0, 32)
|
|
27
|
+
switch (abiType) {
|
|
28
|
+
case 'string':
|
|
29
|
+
const dataLocation = uintData
|
|
30
|
+
if (dataLocation % 32 !== 0) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'Invalid data provided while decoding string: ' +
|
|
33
|
+
'first 32byte word is not a valid address')
|
|
34
|
+
}
|
|
35
|
+
if (dataLocation + 64 > dataBuffer.length) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'Invalid data provided while decoding string: ' +
|
|
38
|
+
'not enough data to decode length and first word at given location')
|
|
39
|
+
}
|
|
40
|
+
const dataLength = dataBuffer.readUIntBE(dataLocation, 32)
|
|
41
|
+
const expectedLength = Math.ceil((dataLocation + 32 + dataLength) / 32) * 32
|
|
42
|
+
console.log("expected:", expectedLength)
|
|
43
|
+
if (dataBuffer.length !== expectedLength) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
'Invalid data provided while decoding string: ' +
|
|
46
|
+
'not enough data to decode advertised string')
|
|
47
|
+
}
|
|
48
|
+
const dataValue = dataBuffer.slice(dataLocation + 32, dataLocation + 32 + dataLength)
|
|
49
|
+
return dataValue.toString()
|
|
50
|
+
case 'uint':
|
|
51
|
+
case 'uint256':
|
|
52
|
+
return uintData
|
|
53
|
+
case 'number/100':
|
|
54
|
+
return (decodeData('number', data) / 100.0).toString()
|
|
55
|
+
case 'number':
|
|
56
|
+
const shortData = '0x' + data.slice(-12)
|
|
57
|
+
let a = parseInt(shortData, 16)
|
|
58
|
+
|
|
59
|
+
if (a > (34359738368 * 4096)) {
|
|
60
|
+
a -= 68719476736 * 4096
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return a
|
|
64
|
+
case 'bool':
|
|
65
|
+
return uintData === 1
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`Unsupported ABI type: ${abiType}`)
|
|
13
68
|
}
|
|
14
|
-
|
|
15
|
-
return a / ratio
|
|
16
69
|
}
|
|
17
70
|
|
|
18
71
|
|
|
@@ -22,13 +75,22 @@ export default abstract class BcReadAbstract {
|
|
|
22
75
|
abstract contracts: string[]
|
|
23
76
|
|
|
24
77
|
// Get Global status of the contract
|
|
25
|
-
|
|
78
|
+
getContractStatus () { return this.read(this.contracts[0], '0x8b3c7c69') }
|
|
26
79
|
// Get Global infos: Tax destinary Account
|
|
27
|
-
|
|
80
|
+
getTaxAccount () { return this.read(this.contracts[0], '0x4f2eabe0') }
|
|
28
81
|
|
|
29
82
|
// Get Historical infos infos: Global balance
|
|
30
83
|
async getHistoricalGlobalBalance (walletAddress, blockNb) {
|
|
31
|
-
|
|
84
|
+
const data = await this.read(
|
|
85
|
+
this.contracts[0], '0x70a08231', [
|
|
86
|
+
getNakedAddress(walletAddress)
|
|
87
|
+
], blockNb)
|
|
88
|
+
return decodeData('number/100', data)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async getVersion () {
|
|
92
|
+
const data = await this.read(this.contracts[0], '0x54fd4d50')
|
|
93
|
+
return decodeData('string', data as string)
|
|
32
94
|
}
|
|
33
95
|
|
|
34
96
|
|
|
@@ -36,46 +98,45 @@ export default abstract class BcReadAbstract {
|
|
|
36
98
|
// Generic read function
|
|
37
99
|
|
|
38
100
|
async getAmount (address, walletAddress) {
|
|
39
|
-
const
|
|
40
|
-
this.contracts[0], address, [
|
|
41
|
-
|
|
42
|
-
|
|
101
|
+
const data = await this.read(
|
|
102
|
+
this.contracts[0], address, [
|
|
103
|
+
getNakedAddress(walletAddress)
|
|
104
|
+
])
|
|
105
|
+
return decodeData('number/100', data)
|
|
43
106
|
}
|
|
44
107
|
|
|
45
108
|
async getAccInfo (address, walletAddress) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return this.ajaxReq.getEthCall(userInfo)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async getAmountAt (address, walletAddress, blockNb) {
|
|
55
|
-
const userInfo = getDataObj(
|
|
56
|
-
this.contracts[0], address, [getNakedAddress(walletAddress)])
|
|
57
|
-
const blockHex = '0x' + new BigNumber(blockNb).toString(16)
|
|
58
|
-
const data = await this.ajaxReq.getEthCallAt(userInfo, blockHex)
|
|
59
|
-
return getNumber(data, 100.0).toString()
|
|
109
|
+
const data = await this.read(
|
|
110
|
+
this.contracts[0], address, [
|
|
111
|
+
getNakedAddress(walletAddress)
|
|
112
|
+
])
|
|
113
|
+
return decodeData('number', data)
|
|
60
114
|
}
|
|
61
115
|
|
|
62
|
-
async
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
116
|
+
async read (contract: string, address: string, args?: any[],
|
|
117
|
+
blockNb: string = 'pending'): Promise<string> {
|
|
118
|
+
args = args || []
|
|
119
|
+
const ethCall = getDataObj(contract, address, args)
|
|
120
|
+
if (blockNb !== 'pending') {
|
|
121
|
+
blockNb = '0x' + new BigNumber(blockNb).toString(16)
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return (await this.ajaxReq.getEthCallAt(ethCall, blockNb)) as string
|
|
125
|
+
} catch (e) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Failed read contract: ${contract}, fn: ${address}`
|
|
128
|
+
)
|
|
129
|
+
}
|
|
67
130
|
}
|
|
68
131
|
|
|
69
132
|
async getAmountForElement (
|
|
70
133
|
contract, functionAddress, callerAddress, elementAddress) {
|
|
71
|
-
const
|
|
72
|
-
contract, functionAddress,
|
|
73
|
-
[
|
|
134
|
+
const data = await this.read(
|
|
135
|
+
contract, functionAddress, [
|
|
74
136
|
getNakedAddress(callerAddress),
|
|
75
137
|
getNakedAddress(elementAddress)
|
|
76
138
|
])
|
|
77
|
-
|
|
78
|
-
return getNumber(data, 100.0).toString()
|
|
139
|
+
return decodeData('number/100', data)
|
|
79
140
|
}
|
|
80
141
|
|
|
81
142
|
async getElementInList (
|
|
@@ -84,19 +145,16 @@ export default abstract class BcReadAbstract {
|
|
|
84
145
|
|
|
85
146
|
if (index < indMin) return list
|
|
86
147
|
|
|
87
|
-
const
|
|
88
|
-
contract, mapFunctionAddress,
|
|
89
|
-
[
|
|
148
|
+
const data = await this.read(
|
|
149
|
+
contract, mapFunctionAddress, [
|
|
90
150
|
getNakedAddress(callerAddress),
|
|
91
151
|
padLeft(new BigNumber(index).toString(16), 64)
|
|
92
152
|
])
|
|
93
|
-
const data: {[k: string]: any} = await this.ajaxReq.getEthCall(userInfo)
|
|
94
|
-
|
|
95
153
|
const amount = await this.getAmountForElement(
|
|
96
154
|
contract, amountFunctionAddress, callerAddress, data)
|
|
97
155
|
|
|
98
|
-
const
|
|
99
|
-
const element = { address
|
|
156
|
+
const address = '0x' + data.substring(data.length - 40)
|
|
157
|
+
const element = { address, amount }
|
|
100
158
|
list.unshift(element)
|
|
101
159
|
return this.getElementInList(
|
|
102
160
|
contract, mapFunctionAddress,
|
|
@@ -165,10 +223,11 @@ for (const key in ListFunction) {
|
|
|
165
223
|
// avoid unwanted infinite loops
|
|
166
224
|
indMax = indMax || 0
|
|
167
225
|
indMin = indMin || 0
|
|
168
|
-
const
|
|
169
|
-
this.contracts[1],
|
|
170
|
-
|
|
171
|
-
|
|
226
|
+
const data = await this.read(
|
|
227
|
+
this.contracts[1], `0x${configList.count}`, [
|
|
228
|
+
getNakedAddress(walletAddress)
|
|
229
|
+
])
|
|
230
|
+
const count = decodeData('number', data)
|
|
172
231
|
const list = []
|
|
173
232
|
const index = Math.min(count - 1, indMax)
|
|
174
233
|
return this.getElementInList(
|
package/src/bcTransaction.ts
CHANGED
|
@@ -13,20 +13,26 @@ function typeConv (label: string): (x:any) => (string | number) {
|
|
|
13
13
|
if (label.endsWith('Address')) {
|
|
14
14
|
return (a) => padLeft(getNakedAddress(a), 64)
|
|
15
15
|
}
|
|
16
|
+
if (label === 'int') {
|
|
17
|
+
return (nb) => encodeNumber(parseInt(nb, 19))
|
|
18
|
+
}
|
|
16
19
|
if (label.startsWith('limit') || label === 'amount') {
|
|
17
20
|
return (nb) => encodeNumber(roundCent(nb))
|
|
18
21
|
}
|
|
19
|
-
if (label.endsWith('Status') || label.endsWith('Type')) {
|
|
22
|
+
if (label.endsWith('Status') || label.endsWith('Type') || label.endsWith('Int')) {
|
|
20
23
|
return (nb) => encodeNumber(nb)
|
|
21
24
|
}
|
|
25
|
+
if (label.endsWith('Hex')) {
|
|
26
|
+
return (s) => s.padEnd(128, '0')
|
|
27
|
+
}
|
|
22
28
|
if (label === 'status') {
|
|
23
|
-
return (nb) => (parseInt(nb, 10) === 0 ? 0 : 1)
|
|
29
|
+
return (nb) => encodeNumber(parseInt(nb, 10) === 0 ? 0 : 1)
|
|
24
30
|
}
|
|
25
31
|
throw new Error(`Unexpected label '${label}' in FnDefs.`)
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
|
|
29
|
-
export
|
|
35
|
+
export abstract class BcTransactionAbstract {
|
|
30
36
|
|
|
31
37
|
abstract ajaxReq: AjaxReq
|
|
32
38
|
abstract contracts: string[]
|
|
@@ -77,81 +83,56 @@ export default abstract class BcTransactionAbstract {
|
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
|
|
80
|
-
[
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
setAccountParam: '848b2592:accAddress accStatus accType limitPlus limitMinus',
|
|
84
|
-
pledgeAccount: '6c343eef:accAddress amount *',
|
|
85
|
-
setAllowance: 'd4e12f2e:spenderAddress amount',
|
|
86
|
-
setDelegation: '75741c79:spenderAddress limit',
|
|
87
|
-
setTaxAmount: 'f6f1897d:amount',
|
|
88
|
-
setTaxLegAmount: 'fafaf4c0:amount',
|
|
89
|
-
setTaxAccount: 'd0385b5e:accAddress',
|
|
90
|
-
setOwnerAccount: 'f2fde38b:accAddress',
|
|
91
|
-
setContractStatus: '0x88b8084f:status',
|
|
92
|
-
},
|
|
93
|
-
// Second Contract
|
|
94
|
-
{
|
|
95
|
-
transferNant: 'a5f7c148:toAddress amount *',
|
|
96
|
-
transferCM: '60ca9c4c:toAddress amount *',
|
|
97
|
-
transferOnBehalfNant: '1b6b1ee5:fromAddress toAddress amount D',
|
|
98
|
-
transferOnBehalfCM: '74c421fe:fromAddress toAddress amount D',
|
|
99
|
-
askTransferFrom: '58258353:fromAddress amount',
|
|
100
|
-
askTransferCMFrom: '2ef9ade2:fromAddress amount',
|
|
101
|
-
payRequestNant: '132019f4:toAddress amount *',
|
|
102
|
-
payRequestCM: '1415707c:toAddress amount *',
|
|
103
|
-
rejectRequest: 'af98f757:toAddress',
|
|
104
|
-
dismissAcceptedInfo: 'ccf93c7a:accAddress',
|
|
105
|
-
dismissRejectedInfo: '88759215:accAddress',
|
|
106
|
-
}
|
|
107
|
-
].forEach((contractFnDefs, contractNb) => {
|
|
108
|
-
|
|
109
|
-
for (const fnName in contractFnDefs) {
|
|
110
|
-
|
|
111
|
-
const [fnHash, argStringList] = contractFnDefs[fnName].split(':')
|
|
112
|
-
const argList = argStringList.split(' ')
|
|
113
|
-
let hasAdditionalPostData = false
|
|
114
|
-
let hasDelegate = false
|
|
115
|
-
if (argList.slice(-1)[0] === '*') {
|
|
116
|
-
hasAdditionalPostData = true
|
|
117
|
-
argList.pop()
|
|
118
|
-
} else if (argList.slice(-1)[0] === 'D') {
|
|
119
|
-
hasAdditionalPostData = true
|
|
120
|
-
hasDelegate = true
|
|
121
|
-
argList.pop()
|
|
122
|
-
}
|
|
86
|
+
export function transactionFactory(transactionDefs: any[], bcTransactionClass: any) {
|
|
87
|
+
|
|
88
|
+
transactionDefs.forEach((contractFnDefs, contractNb) => {
|
|
123
89
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
90
|
+
for (const fnName in contractFnDefs) {
|
|
91
|
+
|
|
92
|
+
const [fnHash, argStringList] = contractFnDefs[fnName].split(':')
|
|
93
|
+
const argList = argStringList.split(' ')
|
|
94
|
+
let hasAdditionalPostData = false
|
|
95
|
+
let hasDelegate = false
|
|
96
|
+
if (argList.slice(-1)[0] === '*') {
|
|
97
|
+
hasAdditionalPostData = true
|
|
98
|
+
argList.pop()
|
|
99
|
+
} else if (argList.slice(-1)[0] === 'D') {
|
|
100
|
+
hasAdditionalPostData = true
|
|
101
|
+
hasDelegate = true
|
|
102
|
+
argList.pop()
|
|
136
103
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
104
|
+
|
|
105
|
+
// Build argument array function
|
|
106
|
+
const argFnList = argList.map((arg) => typeConv(arg))
|
|
107
|
+
const concatArgs = (args) =>
|
|
108
|
+
args.map((arg, idx) => argFnList[idx](arg)).join('')
|
|
109
|
+
|
|
110
|
+
bcTransactionClass.prototype[fnName] = async function (wallet, ...args) {
|
|
111
|
+
const addr = wallet.getAddressString()
|
|
112
|
+
const data = await this.ajaxReq.getTransactionData(addr)
|
|
113
|
+
// TODO: must test this
|
|
114
|
+
if (data.error) {
|
|
115
|
+
console.log(`Failed getTransactionData(${addr})`)
|
|
116
|
+
throw new Error(data.msg)
|
|
117
|
+
}
|
|
118
|
+
const additionalPostData = hasAdditionalPostData ? args.pop() : {}
|
|
119
|
+
if (hasDelegate) {
|
|
120
|
+
additionalPostData.delegate = wallet.getAddressString()
|
|
121
|
+
}
|
|
122
|
+
const rawSignedTx = generateTx({
|
|
123
|
+
gasLimit: 500000,
|
|
124
|
+
data: fnHash + concatArgs(args),
|
|
125
|
+
to: this.contracts[contractNb],
|
|
126
|
+
unit: 'ether',
|
|
127
|
+
value: 0,
|
|
128
|
+
nonce: 1,
|
|
129
|
+
gasPrice: null,
|
|
130
|
+
donate: false,
|
|
131
|
+
from: addr,
|
|
132
|
+
key: wallet.getPrivateKeyString()
|
|
133
|
+
}, data)
|
|
134
|
+
return this.ajaxReq.sendTx(rawSignedTx, additionalPostData)
|
|
140
135
|
}
|
|
141
|
-
const rawTx = generateTx({
|
|
142
|
-
gasLimit: 500000,
|
|
143
|
-
data: fnHash + concatArgs(args),
|
|
144
|
-
to: this.contracts[contractNb],
|
|
145
|
-
unit: 'ether',
|
|
146
|
-
value: 0,
|
|
147
|
-
nonce: 1,
|
|
148
|
-
gasPrice: null,
|
|
149
|
-
donate: false,
|
|
150
|
-
from: addr,
|
|
151
|
-
key: wallet.getPrivateKeyString()
|
|
152
|
-
}, data)
|
|
153
|
-
if (rawTx.isError) return rawTx
|
|
154
|
-
return this.ajaxReq.sendTx(rawTx.signedTx, additionalPostData)
|
|
155
136
|
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
// First Contract
|
|
5
|
+
{
|
|
6
|
+
setAccountParam: '848b2592:accAddress accStatus accType limitPlus limitMinus',
|
|
7
|
+
pledgeAccount: '6c343eef:accAddress amount *',
|
|
8
|
+
setAllowance: 'd4e12f2e:spenderAddress amount',
|
|
9
|
+
setDelegation: '75741c79:spenderAddress limit',
|
|
10
|
+
setTaxAmount: 'f6f1897d:int',
|
|
11
|
+
setTaxLegAmount: 'fafaf4c0:int',
|
|
12
|
+
setTaxAccount: 'd0385b5e:accAddress',
|
|
13
|
+
setOwnerAccount: 'f2fde38b:accAddress',
|
|
14
|
+
setContractStatus: '88b8084f:status',
|
|
15
|
+
},
|
|
16
|
+
// Second Contract
|
|
17
|
+
{
|
|
18
|
+
transferNant: 'a5f7c148:toAddress amount *',
|
|
19
|
+
transferCM: '60ca9c4c:toAddress amount *',
|
|
20
|
+
transferOnBehalfNant: '1b6b1ee5:fromAddress toAddress amount D',
|
|
21
|
+
transferOnBehalfCM: '74c421fe:fromAddress toAddress amount D',
|
|
22
|
+
askTransferFrom: '58258353:fromAddress amount',
|
|
23
|
+
askTransferCMFrom: '2ef9ade2:fromAddress amount',
|
|
24
|
+
payRequestNant: '132019f4:toAddress amount *',
|
|
25
|
+
payRequestCM: '1415707c:toAddress amount *',
|
|
26
|
+
rejectRequest: 'af98f757:toAddress',
|
|
27
|
+
dismissAcceptedInfo: 'ccf93c7a:accAddress',
|
|
28
|
+
dismissRejectedInfo: '88759215:accAddress',
|
|
29
|
+
},
|
|
30
|
+
]
|
package/src/connection.ts
CHANGED
|
@@ -43,8 +43,15 @@ abstract class ConnectionAbstract {
|
|
|
43
43
|
///
|
|
44
44
|
// [Lower level] Get the list of ComChain end-points from given repo
|
|
45
45
|
///
|
|
46
|
-
getCCEndPointList (repo: string) {
|
|
47
|
-
|
|
46
|
+
async getCCEndPointList (repo: string) {
|
|
47
|
+
try {
|
|
48
|
+
return await this.http.get(
|
|
49
|
+
repo + config.nodesRepo,
|
|
50
|
+
{ _: new Date().getTime() })
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error(`Failed to get endpoint list on ${repo}`, e)
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
///
|
|
@@ -232,11 +239,12 @@ export default abstract class ConnectionMgrAbstract extends ConnectionAbstract {
|
|
|
232
239
|
public getLocalConfJSON () {
|
|
233
240
|
if (this.conf) return this.conf
|
|
234
241
|
const cfgJson = this.persistentStore.get('ServerConf')
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
242
|
+
const cfg = cfgJson ? JSON.parse(cfgJson) : {}
|
|
243
|
+
// Completing with other informations if available
|
|
244
|
+
if (this.repo) {
|
|
245
|
+
cfg.repo = this.repo
|
|
246
|
+
cfg.custoRepo = this.repo + config.custoRepo
|
|
247
|
+
}
|
|
240
248
|
return cfg
|
|
241
249
|
}
|
|
242
250
|
|