Skip to content

Commit 036428f

Browse files
Merge pull request #383 from Cryptonomic/as-token-update
Kalamint & HEN NFT support
2 parents db27aa2 + 79080f6 commit 036428f

20 files changed

Lines changed: 1328 additions & 483 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Project [honeybadger](https://github.com/Cryptonomic/honeybadger), which is the
5959
<html>
6060
<head>
6161
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs/dist-web/conseiljs.min.js"
62-
integrity="sha384-bUmP+mbBKqeLslTLtJkngVuA+nVFgEmFy1dkKraoJEHOUGvVRK/cIfhwnFWRM2Lv"
62+
integrity="sha384-00+mCQozoha9AxOWtEN+VW/3vMpSBrANeDsYMEioopddFtFoidSiR3X+B+87l1mP"
6363
crossorigin="anonymous"></script>
6464
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs-softsigner/dist-web/conseiljs-softsigner.min.js"
6565
integrity="sha384-V1iaajn0x/SMFcZ9Y/xNQmqQSKyll6Dzt27U6OWiv8NdbHTVaHOGHdQ8g0G68HPd"

dist-web/conseiljs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 417 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "conseiljs",
3-
"version": "5.0.8-3",
3+
"version": "5.0.9",
44
"description": "Client-side library for Tezos dApp development.",
55
"browser": "dist/index-web.js",
66
"main": "dist/index.js",
@@ -67,10 +67,11 @@
6767
"instrument": true
6868
},
6969
"dependencies": {
70-
"big-integer": "1.6.48",
70+
"big-integer": "1.6.50",
71+
"bignumber.js": "9.0.1",
7172
"blakejs": "1.1.0",
7273
"bs58check": "2.1.2",
73-
"jsonpath-plus": "5.0.2",
74+
"jsonpath-plus": "5.1.0",
7475
"moo": "0.5.0",
7576
"nearley": "2.19.1"
7677
},
@@ -80,25 +81,25 @@
8081
"@types/mocha": "8.2.0",
8182
"@types/nock": "11.1.0",
8283
"@types/node": "14.0.13",
83-
"@types/node-fetch": "2.5.7",
84+
"@types/node-fetch": "3.0.3",
8485
"@typescript-eslint/parser": "3.7.1",
8586
"awesome-typescript-loader": "5.2.1",
8687
"chai": "4.2.0",
8788
"chai-as-promised": "7.1.1",
88-
"conseiljs-softsigner": "5.0.3",
89+
"conseiljs-softsigner": "5.0.4-1",
8990
"copyfiles": "2.3.0",
9091
"coveralls": "3.1.0",
9192
"eslint": "7.18.0",
92-
"glob": "7.1.6",
93+
"glob": "7.2.0",
9394
"loglevel": "1.7.1",
94-
"mocha": "8.2.1",
95-
"nock": "13.0.6",
96-
"node-fetch": "2.6.1",
95+
"mocha": "8.4.0",
96+
"nock": "13.1.3",
97+
"node-fetch": "3.0.0",
9798
"nyc": "15.1.0",
9899
"terser-webpack-plugin": "3.0.8",
99100
"ts-node": "8.10.2",
100101
"tsconfig-paths-webpack-plugin": "3.3.0",
101-
"typedoc": "0.18.0",
102+
"typedoc": "^0.20.36",
102103
"typedoc-plugin-markdown": "2.4.2",
103104
"typescript": "3.8.3",
104105
"webpack": "4.44.2",

src/chain/tezos/TezosMessageUtil.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ export namespace TezosMessageUtils {
361361
return base58check.encode(Buffer.from('02aa' + buffer.toString('hex'), 'hex'));
362362
} else if (hint === 'expr') {
363363
return base58check.encode(Buffer.from('0d2c401b' + buffer.toString('hex'), 'hex'));
364+
} else if (hint === 'chain_id') {
365+
return base58check.encode(Buffer.from('575200' + buffer.toString('hex'), 'hex'));
364366
} else if (hint === '') {
365367
return base58check.encode(buffer);
366368
} else {
@@ -372,9 +374,18 @@ export namespace TezosMessageUtils {
372374
* Writes an arbitrary Base58-check string into hex.
373375
*
374376
* @param b String to convert.
377+
* @param hint Hint to use while encoding, blank will encode the string directly, 'chain_id' will encode a chainid type.
375378
*/
376-
export function writeBufferWithHint(b: string): Buffer {
377-
return base58check.decode(b);
379+
export function writeBufferWithHint(b: string, hint: string = ''): Buffer {
380+
if (hint === '') {
381+
return base58check.decode(b);
382+
}
383+
384+
if (hint === 'chain_id') {
385+
return base58check.decode(b).slice("Net".length);
386+
}
387+
388+
throw new Error(`Unsupported hint, '${hint}'`);
378389
}
379390

380391
/**

src/chain/tezos/TezosNodeReader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { JSONPath } from 'jsonpath-plus';
22

33
import * as TezosRPCTypes from '../../types/tezos/TezosRPCResponseTypes'
44
import { TezosRequestError } from '../../types/tezos/TezosErrorTypes';
5+
import { TezosConstants } from '../../types/tezos/TezosConstants';
56
import FetchSelector from '../../utils/FetchSelector'
67
import LogSelector from '../../utils/LoggerSelector';
78

@@ -183,7 +184,7 @@ export namespace TezosNodeReader {
183184
* @param {string} chainid Chain id, expected to be 'main' or 'test', defaults to main.
184185
*/
185186
export function getValueForBigMapKey(server: string, index: number, key: string, block: string = 'head', chainid: string = 'main'): Promise<any> {
186-
return performGetRequest(server, `chains/${chainid}/blocks/${block}/context/big_maps/${index}/${key}`).catch(err => undefined);
187+
return performGetRequest(server, `chains/${chainid}/blocks/${block}/context/big_maps/${index}/${key}`);
187188
}
188189

189190
/**
@@ -214,7 +215,7 @@ export namespace TezosNodeReader {
214215

215216
var result = await Promise.all([refBlock, headBlock]).then(blocks => Number(blocks[1]['header']['level']) - Number(blocks[0]['header']['level']));
216217

217-
return 64 - result; // TODO: named const
218+
return TezosConstants.MaxBranchOffset - result;
218219
}
219220

220221
/**

src/chain/tezos/TezosNodeWriter.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export namespace TezosNodeWriter {
3838

3939
log.debug(`TezosNodeWriter.performPostRequest sending ${payloadStr}\n->\n${url}`);
4040

41-
return fetch(url, { method: 'post', body: payloadStr, headers: { 'content-type': 'application/json' } });
41+
return fetch(url, { method: 'post', body: payloadStr, headers: { 'Content-Type': 'application/json' } });
4242
}
4343

4444
/**
@@ -269,9 +269,9 @@ export namespace TezosNodeWriter {
269269
});
270270

271271
return [revealOp, ...operations];
272+
} else {
273+
return operations.map((o, i) => { return { ...o, counter: `${counter + i}` } });
272274
}
273-
274-
return operations;
275275
}
276276

277277
/**
@@ -714,8 +714,6 @@ export namespace TezosNodeWriter {
714714
let operationResources: { gas: number, storageCost: number }[] = [];
715715

716716
for (let i = 0; i < operations.length; i++) { // Estimate each operation.
717-
const operation = operations[i];
718-
719717
// Estimate resources used in the set of prior transactions.
720718
// If there were no prior transactions, set resource usage to 0.
721719
let priorConsumedResources = { gas: 0, storageCost: 0 };
@@ -726,7 +724,7 @@ export namespace TezosNodeWriter {
726724

727725
// Estimate resources for everything up to the current transaction. Newer transactions may depend on previous transactions, thus all transactions must be estimated.
728726
const currentTransactions = operations.slice(0, i + 1);
729-
const currentConsumedResources = await TezosNodeWriter.estimateOperation(server, chainid, ...currentTransactions);
727+
const currentConsumedResources = await estimateOperation(server, chainid, ...currentTransactions);
730728

731729
// Find the actual transaction cost by calculating the delta between the two transactions resource usages.
732730
const gasLimitDelta = currentConsumedResources.gas - priorConsumedResources.gas;
@@ -772,7 +770,8 @@ export namespace TezosNodeWriter {
772770
chainid: string,
773771
...operations: TezosP2PMessageTypes.Operation[]
774772
): Promise<{ gas: number, storageCost: number, estimatedFee: number, estimatedStorageBurn: number }> {
775-
const localOperations = [...operations].map(o => { return { gas_limit: TezosConstants.OperationGasCap.toString(), storage_limit: TezosConstants.OperationStorageCap.toString(), ...o } });
773+
const naiveOperationGasCap = Math.min(Math.floor(TezosConstants.BlockGasCap / operations.length), TezosConstants.OperationGasCap).toString();
774+
const localOperations = [...operations].map(o => { return {...o, gas_limit: naiveOperationGasCap, storage_limit: TezosConstants.OperationStorageCap.toString()} });
776775

777776
const responseJSON = await dryRunOperation(server, chainid, ...localOperations);
778777

@@ -866,6 +865,21 @@ export namespace TezosNodeWriter {
866865
return operationGroup;
867866
}
868867

868+
export async function prepareOperationGroup(server: string, keyStore: KeyStore, counter: number, operations: TezosP2PMessageTypes.StackableOperation[], optimizeFee: boolean = false) {
869+
const operationGroup = await appendRevealOperation(server, keyStore.publicKey, keyStore.publicKeyHash, counter, operations);
870+
871+
if (optimizeFee) {
872+
const estimate = await estimateOperationGroup(server, 'main', operationGroup);
873+
operationGroup[0].fee = estimate.estimatedFee.toString();
874+
for (let i = 0; i < operationGroup.length; i++) {
875+
operationGroup[i].gas_limit = estimate.operationResources[i].gas.toString();
876+
operationGroup[i].storage_limit = estimate.operationResources[i].storageCost.toString();
877+
}
878+
}
879+
880+
return operationGroup;
881+
}
882+
869883
/**
870884
* This function checks if the server response contains an error. There are multiple formats for errors coming
871885
* back from the server, this method attempts to normalized them for downstream parsing.

0 commit comments

Comments
 (0)