@keetanetwork/keetanet-client 0.14.0 → 0.14.3
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/README.md +4 -0
- package/api/node.d.ts +1 -0
- package/client/builder.d.ts +8 -3
- package/client/index-browser.d.ts +6 -1
- package/client/index-browser.js +1852 -1723
- package/client/index.d.ts +6 -1
- package/client/index.js +248 -148
- package/docs/GETTING-STARTED.md +361 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/KeetaNetSDK.Client.html +4 -4
- package/docs/classes/KeetaNetSDK.Referenced.BaseSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BaseVoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperation.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationCREATE_IDENTIFIER.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMODIFY_PERMISSIONS.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationRECEIVE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSEND.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_INFO.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_REP.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.CertificateHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSAKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ExternalKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ExternalSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyInterface.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Ledger.html +3 -2
- package/docs/classes/KeetaNetSDK.Referenced.LedgerAtomicInterface.html +2 -1
- package/docs/classes/KeetaNetSDK.Referenced.LedgerStorageTransactionBase.html +8 -0
- package/docs/classes/KeetaNetSDK.Referenced.PermissionSetHolder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Stats.html +10 -4
- package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +10 -0
- package/docs/classes/KeetaNetSDK.Referenced.UserClientBuilder.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.Vote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteStaple.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.UserClient.html +2 -2
- package/docs/documents/GETTING-STARTED.html +3 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLUpdate.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ExplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ImplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1Object.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseExternalKeyPairFunctions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseGenerationConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperation.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationCREATE_IDENTIFIER.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATESerializable.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV1Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV2Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BuilderBlockOptions.html +3 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.Constructor.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.DisposableTimingHandle.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsNoEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsSupportsEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.InitialConfigSupply.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.InstanceSet.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVGenericOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVSetOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.LedgerStorageAPI.html +6 -3
- package/docs/interfaces/KeetaNetSDK.Referenced.LedgerStorageTransactionBaseOptions.html +6 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.ModifyTokenBalanceEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultiSigIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultisigConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.NumericValueEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerListener.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerRepBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.PublicKeyStorage.html +1 -1
- package/docs/interfaces/{KeetaNetSDK.PublishOptions.html → KeetaNetSDK.Referenced.PublishOptions.html} +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.RequestTokenReceiveEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.TokenNumericEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientOptions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.WithIsInstance.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1BitString.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Date.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1OID.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Set.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1String.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.src_lib_utils_asn1.html +1 -1
- package/docs/modules/KeetaNetSDK.html +2 -2
- package/docs/types/KeetaNetSDK.Referenced.GetAccountStateAPIResponseFormatted.html +5 -2
- package/docs/types/KeetaNetSDK.Referenced.GetAccountStateAPIResponseSuccess.html +3 -2
- package/docs/types/KeetaNetSDK.Referenced.src_lib_utils_asn1.ValidateASN1.SchemaMap.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.BlockErrorCodes-1.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.LedgerErrorCodes.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1CheckUtilities.html +1 -0
- package/lib/error/certificate.d.ts +1 -1
- package/lib/error/ledger.d.ts +1 -1
- package/lib/ledger/common.d.ts +9 -0
- package/lib/ledger/db_dynamodb.d.ts +5 -9
- package/lib/ledger/db_postgres.d.ts +11 -3
- package/lib/ledger/db_spanner.d.ts +5 -12
- package/lib/ledger/db_spanner_helper.d.ts +1 -1
- package/lib/ledger/db_sqlite.d.ts +11 -3
- package/lib/ledger/index.d.ts +34 -2
- package/lib/p2p.d.ts +1 -1
- package/lib/stats.d.ts +22 -3
- package/lib/utils/asn1.d.ts +18 -1
- package/lib/utils/static-types.d.ts +11 -0
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/benchmarking/test.d.ts +0 -4
- package/docs/interfaces/KeetaNetSDK.Referenced.LedgerStorageTransactionBase.html +0 -6
package/client/index-browser.js
CHANGED
|
@@ -101264,6 +101264,7 @@ var client_utils_asn1_namespaceObject = {};
|
|
|
101264
101264
|
__webpack_require__.r(client_utils_asn1_namespaceObject);
|
|
101265
101265
|
__webpack_require__.d(client_utils_asn1_namespaceObject, {
|
|
101266
101266
|
ASN1BigIntToBuffer: () => (client_ASN1BigIntToBuffer),
|
|
101267
|
+
ASN1CheckUtilities: () => (client_ASN1CheckUtilities),
|
|
101267
101268
|
ASN1IntegerToBigInt: () => (client_ASN1IntegerToBigInt),
|
|
101268
101269
|
ASN1toJS: () => (client_ASN1toJS),
|
|
101269
101270
|
BufferStorageASN1: () => (client_BufferStorageASN1),
|
|
@@ -113180,7 +113181,16 @@ function client_isASN1Set(input) {
|
|
|
113180
113181
|
}
|
|
113181
113182
|
return true;
|
|
113182
113183
|
}
|
|
113183
|
-
function
|
|
113184
|
+
function client_isASN1ContextTagKind(input) {
|
|
113185
|
+
if (typeof input !== 'string') {
|
|
113186
|
+
return false;
|
|
113187
|
+
}
|
|
113188
|
+
if (!['explicit', 'implicit'].includes(input)) {
|
|
113189
|
+
return false;
|
|
113190
|
+
}
|
|
113191
|
+
return true;
|
|
113192
|
+
}
|
|
113193
|
+
function client_isASN1ContextTag(input, tagKind) {
|
|
113184
113194
|
if (!client_isASN1Object(input)) {
|
|
113185
113195
|
return false;
|
|
113186
113196
|
}
|
|
@@ -113193,6 +113203,12 @@ function client_isASN1ContextTag(input) {
|
|
|
113193
113203
|
if (!('contains' in input) || input.contains === undefined) {
|
|
113194
113204
|
return false;
|
|
113195
113205
|
}
|
|
113206
|
+
if (!('kind' in input) || !client_isASN1ContextTagKind(input.kind)) {
|
|
113207
|
+
return false;
|
|
113208
|
+
}
|
|
113209
|
+
if (tagKind !== undefined && input.kind !== tagKind) {
|
|
113210
|
+
return false;
|
|
113211
|
+
}
|
|
113196
113212
|
return true;
|
|
113197
113213
|
}
|
|
113198
113214
|
function client_isASN1BitString(input) {
|
|
@@ -113249,6 +113265,15 @@ function client_isStringValidForKind(input, kind) {
|
|
|
113249
113265
|
}
|
|
113250
113266
|
return false;
|
|
113251
113267
|
}
|
|
113268
|
+
const client_ASN1CheckUtilities = {
|
|
113269
|
+
isASN1Object: client_isASN1Object,
|
|
113270
|
+
isASN1OID: client_isASN1OID,
|
|
113271
|
+
isASN1String: client_isASN1String,
|
|
113272
|
+
isASN1Set: client_isASN1Set,
|
|
113273
|
+
isASN1ContextTag: client_isASN1ContextTag,
|
|
113274
|
+
isASN1BitString: client_isASN1BitString,
|
|
113275
|
+
isASN1Date: client_isASN1Date
|
|
113276
|
+
};
|
|
113252
113277
|
|
|
113253
113278
|
/**
|
|
113254
113279
|
* Validation function for {@link isValidSequenceSchema}
|
|
@@ -115300,7 +115325,7 @@ function client_certificate_toPrimitive(t, r) { if ("object" != typeof t || !t)
|
|
|
115300
115325
|
|
|
115301
115326
|
|
|
115302
115327
|
const client_CertificateErrorType = 'CERTIFICATE';
|
|
115303
|
-
const client_certificate_BlockErrorCodes = ['DUPLICATE_INCLUDED', 'ORPHAN_FOUND', 'CYCLE_FOUND', 'SECONDARY_GRAPH'];
|
|
115328
|
+
const client_certificate_BlockErrorCodes = ['DUPLICATE_INCLUDED', 'ORPHAN_FOUND', 'CYCLE_FOUND', 'SECONDARY_GRAPH', 'MISSING_FIELD', 'SIGNATURE_ALGORITHM_MISMATCH', 'SELF_SIGNED_VALIDATION_FAILED', 'CHAIN_VERIFICATION_FAILED', 'DUPLICATE_EXTENSION', 'EXTENSION_NOT_PROCESSED', 'INVALID_SIGNATURE_ALGORITHM', 'INVALID_GRAPH_COUNT', 'MOMENT_INVALID', 'INVALID_VERSION'];
|
|
115304
115329
|
class src_client_KeetaNetCertificateError extends src_client_KeetaNetError {
|
|
115305
115330
|
constructor(code, message) {
|
|
115306
115331
|
super(code, message, {
|
|
@@ -115473,7 +115498,7 @@ class client_CertificateBuilder {
|
|
|
115473
115498
|
case 'sha3-256':
|
|
115474
115499
|
return hashLib.name;
|
|
115475
115500
|
default:
|
|
115476
|
-
throw new Error(`Unsupported hash algorithm "${hashLib.name}"`);
|
|
115501
|
+
throw new Error(`internal error: Unsupported hash algorithm "${hashLib.name}"`);
|
|
115477
115502
|
}
|
|
115478
115503
|
}
|
|
115479
115504
|
const hashName = (_params$hashParams$de = (_params$hashParams = params.hashParams) === null || _params$hashParams === void 0 || (_params$hashParams = _params$hashParams.defaults) === null || _params$hashParams === void 0 ? void 0 : _params$hashParams[purpose]) !== null && _params$hashParams$de !== void 0 ? _params$hashParams$de : client_defaultHashName;
|
|
@@ -115496,7 +115521,7 @@ class client_CertificateBuilder {
|
|
|
115496
115521
|
const hashName = this.hashName(params, purpose);
|
|
115497
115522
|
const hashFunction = (_params$hashParams$fu = params.hashParams.functions) === null || _params$hashParams$fu === void 0 ? void 0 : _params$hashParams$fu[hashName];
|
|
115498
115523
|
if (hashFunction === undefined) {
|
|
115499
|
-
throw new Error(`Hash function "${hashName}" not found for purpose "${purpose}"`);
|
|
115524
|
+
throw new Error(`internal error: Hash function "${hashName}" not found for purpose "${purpose}"`);
|
|
115500
115525
|
}
|
|
115501
115526
|
return hashFunction(...data);
|
|
115502
115527
|
}
|
|
@@ -115604,28 +115629,28 @@ class client_CertificateBuilder {
|
|
|
115604
115629
|
/* Validate that required parameters are set */
|
|
115605
115630
|
const issuer = finalParams.issuer;
|
|
115606
115631
|
if (issuer === undefined) {
|
|
115607
|
-
throw new
|
|
115632
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"issuer" not set');
|
|
115608
115633
|
}
|
|
115609
115634
|
const subjectPublicKey = finalParams.subjectPublicKey;
|
|
115610
115635
|
if (subjectPublicKey === undefined) {
|
|
115611
|
-
throw new
|
|
115636
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"subject" not set');
|
|
115612
115637
|
}
|
|
115613
115638
|
const validFrom = finalParams.validFrom;
|
|
115614
115639
|
if (validFrom === undefined) {
|
|
115615
|
-
throw new
|
|
115640
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"validFrom" not set');
|
|
115616
115641
|
}
|
|
115617
115642
|
const validTo = finalParams.validTo;
|
|
115618
115643
|
if (validTo === undefined) {
|
|
115619
|
-
throw new
|
|
115644
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"validTo" not set');
|
|
115620
115645
|
}
|
|
115621
115646
|
const serial = finalParams.serial;
|
|
115622
115647
|
if (serial === undefined) {
|
|
115623
|
-
throw new
|
|
115648
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"serialNumber" not set');
|
|
115624
115649
|
}
|
|
115625
115650
|
const hashLib = finalParams.hashLib;
|
|
115626
115651
|
const hashParams = finalParams.hashParams;
|
|
115627
115652
|
if (hashParams === undefined) {
|
|
115628
|
-
throw new
|
|
115653
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MISSING_FIELD', '"hashParams" not set');
|
|
115629
115654
|
}
|
|
115630
115655
|
return {
|
|
115631
115656
|
...finalParams,
|
|
@@ -115967,7 +115992,7 @@ class src_client_Certificate {
|
|
|
115967
115992
|
const tbsCertificate = parts[0];
|
|
115968
115993
|
const [version, serialNumber, signatureAlgorithmSigned, _issuer, [notBefore, notAfter], subject, subjectPublicKey, _extensions] = tbsCertificate;
|
|
115969
115994
|
if (version.contains !== 2n) {
|
|
115970
|
-
throw new
|
|
115995
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_INVALID_VERSION', 'Only X509v3 certificates are supported');
|
|
115971
115996
|
}
|
|
115972
115997
|
const signatureAlgorithm = parts[1];
|
|
115973
115998
|
|
|
@@ -116012,7 +116037,7 @@ class src_client_Certificate {
|
|
|
116012
116037
|
const signatureAlgorithmSignedBuffer = new client_BufferStorageASN1(signatureAlgorithmSigned).getDERBuffer();
|
|
116013
116038
|
const signatureAlgorithmBuffer = new client_BufferStorageASN1(signatureAlgorithm).getDERBuffer();
|
|
116014
116039
|
if (!signatureAlgorithmSignedBuffer.equals(signatureAlgorithmBuffer)) {
|
|
116015
|
-
throw new
|
|
116040
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_SIGNATURE_ALGORITHM_MISMATCH', 'Signature algorithm mismatch between signature and certificate');
|
|
116016
116041
|
}
|
|
116017
116042
|
|
|
116018
116043
|
/*
|
|
@@ -116044,7 +116069,7 @@ class src_client_Certificate {
|
|
|
116044
116069
|
}
|
|
116045
116070
|
});
|
|
116046
116071
|
if (!found) {
|
|
116047
|
-
throw new
|
|
116072
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_SELF_SIGNED_VALIDATION_FAILED', 'Self-signed certificate is not a root CA in the Root CA store');
|
|
116048
116073
|
}
|
|
116049
116074
|
this.chain = [this];
|
|
116050
116075
|
}
|
|
@@ -116053,7 +116078,7 @@ class src_client_Certificate {
|
|
|
116053
116078
|
this.chain = [this];
|
|
116054
116079
|
}
|
|
116055
116080
|
if (!this.verify(this)) {
|
|
116056
|
-
throw new
|
|
116081
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_SELF_SIGNED_VALIDATION_FAILED', 'Self-signed certificate signature verification failed');
|
|
116057
116082
|
}
|
|
116058
116083
|
} else {
|
|
116059
116084
|
/*
|
|
@@ -116062,7 +116087,7 @@ class src_client_Certificate {
|
|
|
116062
116087
|
if ((options === null || options === void 0 ? void 0 : options.store) !== undefined) {
|
|
116063
116088
|
const chain = this.verifyChain(options.store);
|
|
116064
116089
|
if (chain === null || chain.length === 0) {
|
|
116065
|
-
throw new
|
|
116090
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_CHAIN_VERIFICATION_FAILED', 'Certificate chain verification failed');
|
|
116066
116091
|
}
|
|
116067
116092
|
this.chain = chain;
|
|
116068
116093
|
}
|
|
@@ -116130,7 +116155,7 @@ class src_client_Certificate {
|
|
|
116130
116155
|
compatibleKeyTypes = [client_lib_account.AccountKeyAlgorithm.ED25519];
|
|
116131
116156
|
break;
|
|
116132
116157
|
default:
|
|
116133
|
-
throw new
|
|
116158
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_INVALID_SIGNATURE_ALGORITHM', `Unsupported signature algorithm ${signatureAlgorithm}`);
|
|
116134
116159
|
}
|
|
116135
116160
|
let hashAlgorithm;
|
|
116136
116161
|
switch (signatureAlgorithm) {
|
|
@@ -116144,7 +116169,7 @@ class src_client_Certificate {
|
|
|
116144
116169
|
hashAlgorithm = null;
|
|
116145
116170
|
break;
|
|
116146
116171
|
default:
|
|
116147
|
-
throw new
|
|
116172
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_INVALID_SIGNATURE_ALGORITHM', `Unsupported signature algorithm ${signatureAlgorithm}`);
|
|
116148
116173
|
}
|
|
116149
116174
|
let accountIsCompatible = false;
|
|
116150
116175
|
for (const checkCompatibleKeyType of compatibleKeyTypes) {
|
|
@@ -116154,7 +116179,7 @@ class src_client_Certificate {
|
|
|
116154
116179
|
}
|
|
116155
116180
|
}
|
|
116156
116181
|
if (!accountIsCompatible) {
|
|
116157
|
-
throw new
|
|
116182
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_INVALID_SIGNATURE_ALGORITHM', `Account does not have a compatible key type for signature algorithm ${signatureAlgorithm}`);
|
|
116158
116183
|
}
|
|
116159
116184
|
let dataToVerify;
|
|
116160
116185
|
if (hashAlgorithm !== null) {
|
|
@@ -116181,7 +116206,7 @@ class src_client_Certificate {
|
|
|
116181
116206
|
return true;
|
|
116182
116207
|
}
|
|
116183
116208
|
if (certificates.size > 10) {
|
|
116184
|
-
throw new
|
|
116209
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_INVALID_GRAPH_COUNT', 'Cannot currently handle more than 10 certificates in a graph');
|
|
116185
116210
|
}
|
|
116186
116211
|
const issuersFrom = [];
|
|
116187
116212
|
const issuersTo = [];
|
|
@@ -116302,7 +116327,7 @@ class src_client_Certificate {
|
|
|
116302
116327
|
assertValid(moment) {
|
|
116303
116328
|
const valid = this.checkValid(moment, true);
|
|
116304
116329
|
if (!valid.valid) {
|
|
116305
|
-
throw new
|
|
116330
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_MOMENT_INVALID', `Certificate is not valid: ${valid.reason}`);
|
|
116306
116331
|
}
|
|
116307
116332
|
}
|
|
116308
116333
|
|
|
@@ -116376,7 +116401,7 @@ class src_client_Certificate {
|
|
|
116376
116401
|
}
|
|
116377
116402
|
assertConstructed() {
|
|
116378
116403
|
if (!client_certificate_classPrivateFieldGet(client_finalizeConstructionCalled, this)) {
|
|
116379
|
-
throw new Error('finalizeConstruction not called');
|
|
116404
|
+
throw new Error('internal error: finalizeConstruction not called');
|
|
116380
116405
|
}
|
|
116381
116406
|
}
|
|
116382
116407
|
|
|
@@ -116519,7 +116544,7 @@ function client_processBaseExtensions(extensionsObject) {
|
|
|
116519
116544
|
for (const extension of extensions) {
|
|
116520
116545
|
const id = extension[0].oid;
|
|
116521
116546
|
if (seenExtensions.has(id)) {
|
|
116522
|
-
throw new
|
|
116547
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_DUPLICATE_EXTENSION', `Duplicate extension ${id}`);
|
|
116523
116548
|
}
|
|
116524
116549
|
seenExtensions.add(id);
|
|
116525
116550
|
}
|
|
@@ -116590,7 +116615,7 @@ function client_assertAllCriticalExtensionsProcessed() {
|
|
|
116590
116615
|
[id] = extension;
|
|
116591
116616
|
}
|
|
116592
116617
|
if (critical && !client_certificate_classPrivateFieldGet(client_extensionsProcessed, this).has(id.oid)) {
|
|
116593
|
-
throw new
|
|
116618
|
+
throw new src_client_KeetaNetCertificateError('CERTIFICATE_EXTENSION_NOT_PROCESSED', `Critical extension ${id.oid} not processed`);
|
|
116594
116619
|
}
|
|
116595
116620
|
}
|
|
116596
116621
|
}
|
|
@@ -116718,7 +116743,7 @@ function client_ledger_toPrimitive(t, r) { if ("object" != typeof t || !t) retur
|
|
|
116718
116743
|
|
|
116719
116744
|
|
|
116720
116745
|
const client_LedgerErrorType = 'LEDGER';
|
|
116721
|
-
const client_LedgerErrorCodes = ['TRANSACTION_ABORTED', 'INVALID_CHAIN', 'INVALID_NETWORK', 'INVALID_SUBNET', 'NOT_EMPTY', 'NOT_OPENING', 'NOT_SUCCESSOR', 'INVALID_PERMISSIONS', 'INVALID_OWNER_COUNT', 'INVALID_BALANCE', 'PREVIOUS_ALREADY_USED', 'PREVIOUS_NOT_SEEN', 'SUCCESSOR_VOTE_EXISTS', 'INSUFFICIENT_VOTING_WEIGHT', 'INVALID_ACCOUNT_INFO_KEY', 'RECEIVE_NOT_MET', 'DUPLICATE_VOTE_FOUND', 'CANNOT_EXCHANGE_PERM_VOTE', 'BLOCKS_DIFFER_FROM_VOTED_ON', 'NO_PERM_WITHOUT_SELF_TEMP', 'DUPLICATE_VOTE_ISSUER_FOUND', 'OTHER', 'MISSING_BLOCKS',
|
|
116746
|
+
const client_LedgerErrorCodes = ['BLOCK_ALREADY_EXISTS', 'TRANSACTION_ABORTED', 'INVALID_CHAIN', 'INVALID_NETWORK', 'INVALID_SUBNET', 'NOT_EMPTY', 'NOT_OPENING', 'NOT_SUCCESSOR', 'INVALID_PERMISSIONS', 'INVALID_OWNER_COUNT', 'INVALID_BALANCE', 'PREVIOUS_ALREADY_USED', 'PREVIOUS_NOT_SEEN', 'SUCCESSOR_VOTE_EXISTS', 'INSUFFICIENT_VOTING_WEIGHT', 'INVALID_ACCOUNT_INFO_KEY', 'RECEIVE_NOT_MET', 'DUPLICATE_VOTE_FOUND', 'CANNOT_EXCHANGE_PERM_VOTE', 'BLOCKS_DIFFER_FROM_VOTED_ON', 'NO_PERM_WITHOUT_SELF_TEMP', 'DUPLICATE_VOTE_ISSUER_FOUND', 'OTHER', 'MISSING_BLOCKS',
|
|
116722
116747
|
// Fee Errors
|
|
116723
116748
|
'FEE_AMOUNT_MISMATCH', 'FEE_TOKEN_MISMATCH', 'FEE_MISSING', 'MISSING_REQUIRED_FEE_BLOCK', 'PERM_VOTE_WITH_QUOTE', 'QUOTE_MISMATCH', 'REQUIRED_FEE_MISMATCH'];
|
|
116724
116749
|
class client_ledger_KeetaNetLedgerError extends src_client_KeetaNetError {
|
|
@@ -117247,10 +117272,36 @@ class client_LedgerStorageBase {
|
|
|
117247
117272
|
}));
|
|
117248
117273
|
return Object.fromEntries(response);
|
|
117249
117274
|
}
|
|
117275
|
+
async getAccountsBlockHeightInfo(transaction, toFetch) {
|
|
117276
|
+
const response = await Promise.all(toFetch.map(async _ref2 => {
|
|
117277
|
+
let {
|
|
117278
|
+
blockHash,
|
|
117279
|
+
account
|
|
117280
|
+
} = _ref2;
|
|
117281
|
+
if (blockHash === undefined) {
|
|
117282
|
+
const block = await this.getHeadBlock(transaction, account, 'main');
|
|
117283
|
+
if (block !== null) {
|
|
117284
|
+
blockHash = block.hash;
|
|
117285
|
+
}
|
|
117286
|
+
}
|
|
117287
|
+
const retval = [];
|
|
117288
|
+
if (blockHash === undefined) {
|
|
117289
|
+
retval.push(...[account.publicKeyString.get(), null]);
|
|
117290
|
+
} else {
|
|
117291
|
+
const height = await this.getBlockHeight(transaction, blockHash, account);
|
|
117292
|
+
retval.push(...[account.publicKeyString.get(), {
|
|
117293
|
+
blockHash,
|
|
117294
|
+
height
|
|
117295
|
+
}]);
|
|
117296
|
+
}
|
|
117297
|
+
return retval;
|
|
117298
|
+
}));
|
|
117299
|
+
return Object.fromEntries(response);
|
|
117300
|
+
}
|
|
117250
117301
|
async getHeadBlockHashes(transaction, accounts) {
|
|
117251
117302
|
const received = await this.getHeadBlocks(transaction, accounts.toArray(), 'both');
|
|
117252
|
-
return Object.fromEntries(Object.entries(received).map(function (
|
|
117253
|
-
let [account, value] =
|
|
117303
|
+
return Object.fromEntries(Object.entries(received).map(function (_ref3) {
|
|
117304
|
+
let [account, value] = _ref3;
|
|
117254
117305
|
if (value) {
|
|
117255
117306
|
return [account, value.hash];
|
|
117256
117307
|
} else {
|
|
@@ -117261,6 +117312,20 @@ class client_LedgerStorageBase {
|
|
|
117261
117312
|
async preAdjust(input) {
|
|
117262
117313
|
let mayDefer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
117263
117314
|
let transaction = arguments.length > 2 ? arguments[2] : undefined;
|
|
117315
|
+
const allBlockHeightsToFetch = input.blocks.map(block => {
|
|
117316
|
+
return {
|
|
117317
|
+
blockHash: block.hash,
|
|
117318
|
+
account: block.account
|
|
117319
|
+
};
|
|
117320
|
+
});
|
|
117321
|
+
const allBlockHeights = await this.getBlockHeights(transaction, allBlockHeightsToFetch);
|
|
117322
|
+
|
|
117323
|
+
// Check if any blocks already exist on the ledger that would cause this staple to fail and exit early
|
|
117324
|
+
for (const [blockHash, blockHeight] of Object.entries(allBlockHeights)) {
|
|
117325
|
+
if (blockHeight !== null) {
|
|
117326
|
+
throw new KeetaNetLedgerError('LEDGER_BLOCK_ALREADY_EXISTS', `Block Already Exists: ${blockHash.toString()}`);
|
|
117327
|
+
}
|
|
117328
|
+
}
|
|
117264
117329
|
const seenBlockHashes = new BlockHash.Set();
|
|
117265
117330
|
const blockHeights = {};
|
|
117266
117331
|
const toFetch = [];
|
|
@@ -118688,37 +118753,18 @@ function client_ExportBlockOperations(operations) {
|
|
|
118688
118753
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
118689
118754
|
return container;
|
|
118690
118755
|
}
|
|
118691
|
-
function client_assertExplicitContextValueLike(input) {
|
|
118692
|
-
if (typeof input !== 'object' || input === null) {
|
|
118693
|
-
throw new Error(`Found entry which is not a context ${String(input)}`);
|
|
118694
|
-
}
|
|
118695
|
-
if (!('type' in input) || input.type !== 'context') {
|
|
118696
|
-
throw new Error(`Found entry which is not a context ${String(input)}`);
|
|
118697
|
-
}
|
|
118698
|
-
if (!('kind' in input) || input.kind !== 'explicit') {
|
|
118699
|
-
throw new Error(`Found entry which is not an explicit context ${String(input)}`);
|
|
118700
|
-
}
|
|
118701
|
-
if (!('value' in input)) {
|
|
118702
|
-
throw new Error(`Found entry which is not a numeric explicit context ${String(input)}`);
|
|
118703
|
-
}
|
|
118704
|
-
const typeInput = input.value;
|
|
118705
|
-
if (typeof typeInput !== 'number') {
|
|
118706
|
-
throw new Error(`Found entry which is not a numeric explicit context ${String(input)}`);
|
|
118707
|
-
}
|
|
118708
|
-
if (!('contains' in input)) {
|
|
118709
|
-
throw new Error(`Found entry which which lacks contains ${JSON.stringify(input)}`);
|
|
118710
|
-
}
|
|
118711
|
-
if (!Array.isArray(input.contains)) {
|
|
118712
|
-
throw new Error(`Found entry which is not a Sequence ${input.contains}`);
|
|
118713
|
-
}
|
|
118714
|
-
}
|
|
118715
118756
|
function client_ImportOperationsASN1(input, network) {
|
|
118716
118757
|
const retval = [];
|
|
118717
118758
|
for (const entryWrapper of input) {
|
|
118718
118759
|
const operation = {};
|
|
118719
|
-
|
|
118760
|
+
if (!client_ASN1CheckUtilities.isASN1ContextTag(entryWrapper, 'explicit')) {
|
|
118761
|
+
throw new Error('Invalid createArgs type for CREATE_IDENTIFIER operation');
|
|
118762
|
+
}
|
|
118720
118763
|
const type = client_assertOperationType(entryWrapper.value);
|
|
118721
118764
|
const entry = entryWrapper.contains;
|
|
118765
|
+
if (!Array.isArray(entry)) {
|
|
118766
|
+
throw new Error(`Found entry which is not a Sequence ${typeof entry}`);
|
|
118767
|
+
}
|
|
118722
118768
|
const typeStr = client_operationTypeToString(type);
|
|
118723
118769
|
const operationSchema = client_BlockOperationASN1SchemaBase[typeStr];
|
|
118724
118770
|
if (!operationSchema) {
|
|
@@ -118747,16 +118793,24 @@ function client_ImportOperationsASN1(input, network) {
|
|
|
118747
118793
|
newKeyValue.validate(network);
|
|
118748
118794
|
keyValueOut = newKeyValue;
|
|
118749
118795
|
} else if (key === 'createArguments' && typeStr === 'CREATE_IDENTIFIER') {
|
|
118750
|
-
|
|
118796
|
+
if (!client_ASN1CheckUtilities.isASN1ContextTag(keyValueIn, 'explicit')) {
|
|
118797
|
+
throw new Error('Invalid createArgs type for CREATE_IDENTIFIER operation');
|
|
118798
|
+
}
|
|
118751
118799
|
if (keyValueIn.value !== client_AccountKeyAlgorithm.MULTISIG) {
|
|
118752
118800
|
throw new Error('unrecognized type for multisig create arguments');
|
|
118753
118801
|
}
|
|
118754
|
-
if (keyValueIn.contains.length !== 2
|
|
118802
|
+
if (!Array.isArray(keyValueIn.contains) || keyValueIn.contains.length !== 2) {
|
|
118803
|
+
throw new Error('Invalid createArgs container');
|
|
118804
|
+
}
|
|
118805
|
+
if (!Array.isArray(keyValueIn.contains[0])) {
|
|
118755
118806
|
throw new Error('Invalid createArgs container');
|
|
118756
118807
|
}
|
|
118757
118808
|
keyValueOut = {
|
|
118758
118809
|
type: keyValueIn.value,
|
|
118759
118810
|
signers: keyValueIn.contains[0].map(function (value) {
|
|
118811
|
+
if (!client_operations_Buffer.isBuffer(value)) {
|
|
118812
|
+
throw new Error(`Invalid signer value, expected Buffer, got ${typeof value}`);
|
|
118813
|
+
}
|
|
118760
118814
|
return client_lib_account.fromPublicKeyAndType(value);
|
|
118761
118815
|
}),
|
|
118762
118816
|
quorum: keyValueIn.contains[1]
|
|
@@ -125017,1855 +125071,1910 @@ class client_RequestTiming {
|
|
|
125017
125071
|
}
|
|
125018
125072
|
client_timing_defineProperty(client_RequestTiming, "defaultLogger", console);
|
|
125019
125073
|
/* harmony default export */ const src_client_timing = (client_RequestTiming);
|
|
125020
|
-
;// ./src/lib/
|
|
125021
|
-
|
|
125022
|
-
function
|
|
125023
|
-
function
|
|
125024
|
-
function client_lib_ledger_toPropertyKey(t) { var i = client_lib_ledger_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
125025
|
-
function client_lib_ledger_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
125026
|
-
function client_ledger_classPrivateMethodInitSpec(e, a) { client_ledger_checkPrivateRedeclaration(e, a), a.add(e); }
|
|
125027
|
-
function client_ledger_classPrivateFieldInitSpec(e, t, a) { client_ledger_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
125028
|
-
function client_ledger_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
125029
|
-
function client_ledger_classPrivateFieldGet(s, a) { return s.get(client_ledger_assertClassBrand(s, a)); }
|
|
125030
|
-
function client_ledger_classPrivateFieldSet(s, a, r) { return s.set(client_ledger_assertClassBrand(s, a), r), r; }
|
|
125031
|
-
function client_ledger_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
125032
|
-
|
|
125033
|
-
|
|
125034
|
-
|
|
125035
|
-
|
|
125036
|
-
|
|
125037
|
-
|
|
125038
|
-
|
|
125039
|
-
|
|
125040
|
-
|
|
125041
|
-
|
|
125042
|
-
|
|
125043
|
-
|
|
125044
|
-
|
|
125045
|
-
/**
|
|
125046
|
-
* Kind of ledger
|
|
125047
|
-
*/
|
|
125048
|
-
let client_LedgerKind = /*#__PURE__*/function (LedgerKind) {
|
|
125049
|
-
LedgerKind[LedgerKind["REPRESENTATIVE"] = 0] = "REPRESENTATIVE";
|
|
125050
|
-
LedgerKind[LedgerKind["ACCOUNT"] = 1] = "ACCOUNT";
|
|
125051
|
-
return LedgerKind;
|
|
125052
|
-
}({});
|
|
125053
|
-
|
|
125054
|
-
/**
|
|
125055
|
-
* Ledger configuration
|
|
125056
|
-
*/
|
|
125057
|
-
|
|
125058
|
-
/**
|
|
125059
|
-
* Which ledger to store this data in
|
|
125060
|
-
*/
|
|
125061
|
-
|
|
125062
|
-
/**
|
|
125063
|
-
* Which ledger(s) to pull the data from
|
|
125064
|
-
*/
|
|
125065
|
-
|
|
125066
|
-
/**
|
|
125067
|
-
* A set of votes and a pointer to the next set/page
|
|
125068
|
-
*/
|
|
125069
|
-
|
|
125070
|
-
/**
|
|
125071
|
-
* Options for "getVotesAfter"
|
|
125072
|
-
*/
|
|
125073
|
-
|
|
125074
|
-
/**
|
|
125075
|
-
* Each transaction can contain the node object making the request to access things like timing information
|
|
125076
|
-
*/
|
|
125077
|
-
|
|
125078
|
-
/**
|
|
125079
|
-
* Each Ledger Storage backend must implement this interface
|
|
125080
|
-
*/
|
|
125081
|
-
var client_network = /*#__PURE__*/new WeakMap();
|
|
125082
|
-
var client_subnet = /*#__PURE__*/new WeakMap();
|
|
125083
|
-
var client_kind = /*#__PURE__*/new WeakMap();
|
|
125084
|
-
var client_ledger_privateKey = /*#__PURE__*/new WeakMap();
|
|
125085
|
-
var client_computeFeeFromBlocks = /*#__PURE__*/new WeakMap();
|
|
125086
|
-
var client_ledger_storage = /*#__PURE__*/new WeakMap();
|
|
125087
|
-
var src_client_ledger = /*#__PURE__*/new WeakMap();
|
|
125088
|
-
var src_client_cache = /*#__PURE__*/new WeakMap();
|
|
125089
|
-
var client_transaction = /*#__PURE__*/new WeakMap();
|
|
125090
|
-
var client_LedgerAtomicInterface_brand = /*#__PURE__*/new WeakSet();
|
|
125091
|
-
/**
|
|
125092
|
-
* Atomic transactional interface to a storage backend
|
|
125093
|
-
*/
|
|
125094
|
-
class client_LedgerAtomicInterface {
|
|
125095
|
-
constructor(_transaction2, storage, config, ledger) {
|
|
125096
|
-
client_ledger_classPrivateMethodInitSpec(this, client_LedgerAtomicInterface_brand);
|
|
125097
|
-
client_ledger_classPrivateFieldInitSpec(this, client_network, void 0);
|
|
125098
|
-
client_ledger_classPrivateFieldInitSpec(this, client_subnet, void 0);
|
|
125099
|
-
client_ledger_classPrivateFieldInitSpec(this, client_kind, void 0);
|
|
125100
|
-
client_ledger_classPrivateFieldInitSpec(this, client_ledger_privateKey, void 0);
|
|
125101
|
-
client_ledger_classPrivateFieldInitSpec(this, client_computeFeeFromBlocks, void 0);
|
|
125102
|
-
client_ledger_classPrivateFieldInitSpec(this, client_ledger_storage, void 0);
|
|
125103
|
-
client_ledger_classPrivateFieldInitSpec(this, src_client_ledger, void 0);
|
|
125104
|
-
client_ledger_classPrivateFieldInitSpec(this, src_client_cache, void 0);
|
|
125105
|
-
client_ledger_classPrivateFieldInitSpec(this, client_transaction, void 0);
|
|
125106
|
-
client_ledger_classPrivateFieldSet(client_network, this, config.network);
|
|
125107
|
-
client_ledger_classPrivateFieldSet(client_subnet, this, config.subnet);
|
|
125108
|
-
client_ledger_classPrivateFieldSet(client_kind, this, config.kind);
|
|
125109
|
-
client_ledger_classPrivateFieldSet(client_ledger_privateKey, this, config.privateKey);
|
|
125110
|
-
client_ledger_classPrivateFieldSet(client_computeFeeFromBlocks, this, config.computeFeeFromBlocks);
|
|
125111
|
-
client_ledger_classPrivateFieldSet(src_client_ledger, this, ledger);
|
|
125112
|
-
client_ledger_classPrivateFieldSet(client_ledger_storage, this, storage);
|
|
125113
|
-
client_ledger_classPrivateFieldSet(client_transaction, this, _transaction2);
|
|
125074
|
+
;// ./src/lib/kv/index.ts
|
|
125075
|
+
function client_kv_defineProperty(e, r, t) { return (r = client_kv_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
125076
|
+
function client_kv_toPropertyKey(t) { var i = client_kv_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
125077
|
+
function client_kv_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
125114
125078
|
|
|
125115
|
-
|
|
125116
|
-
|
|
125117
|
-
|
|
125118
|
-
|
|
125119
|
-
|
|
125120
|
-
|
|
125121
|
-
|
|
125122
|
-
if (existingCache !== undefined) {
|
|
125123
|
-
client_ledger_classPrivateFieldSet(src_client_cache, this, existingCache);
|
|
125124
|
-
} else {
|
|
125125
|
-
client_ledger_classPrivateFieldSet(src_client_cache, this, new client_cache());
|
|
125079
|
+
class client_KVStorageProviderBase {
|
|
125080
|
+
constructor() {
|
|
125081
|
+
client_kv_defineProperty(this, "id", (0,client_lib_crypto.randomUUID)());
|
|
125082
|
+
}
|
|
125083
|
+
async xor(_ignored_arena, key, _ignored_change, _ignored_options) {
|
|
125084
|
+
if (key.startsWith('@buffer:')) {
|
|
125085
|
+
return;
|
|
125126
125086
|
}
|
|
125087
|
+
throw new Error('Key provided for XOR must begin with "@buffer"');
|
|
125127
125088
|
}
|
|
125128
|
-
|
|
125129
|
-
|
|
125130
|
-
|
|
125131
|
-
|
|
125089
|
+
}
|
|
125090
|
+
;// ./src/lib/kv/kv_memory.ts
|
|
125091
|
+
function client_kv_memory_classPrivateMethodInitSpec(e, a) { client_kv_memory_checkPrivateRedeclaration(e, a), a.add(e); }
|
|
125092
|
+
function client_kv_memory_classPrivateFieldInitSpec(e, t, a) { client_kv_memory_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
125093
|
+
function client_kv_memory_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
125094
|
+
function client_kv_memory_classPrivateFieldGet(s, a) { return s.get(client_kv_memory_assertClassBrand(s, a)); }
|
|
125095
|
+
function client_kv_memory_classPrivateFieldSet(s, a, r) { return s.set(client_kv_memory_assertClassBrand(s, a), r), r; }
|
|
125096
|
+
function client_kv_memory_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
125097
|
+
|
|
125098
|
+
|
|
125099
|
+
const client_nullArena = 'null:43c98976-2282-44c2-819a-769732ceb847';
|
|
125100
|
+
function client_deserialize(value) {
|
|
125101
|
+
if (src_client_BufferStorage.isInstance(value)) {
|
|
125102
|
+
value = value.toString('hex');
|
|
125132
125103
|
}
|
|
125133
|
-
|
|
125134
|
-
|
|
125135
|
-
|
|
125136
|
-
|
|
125104
|
+
return value;
|
|
125105
|
+
}
|
|
125106
|
+
var client_db = /*#__PURE__*/new WeakMap();
|
|
125107
|
+
var client_KVStorageProviderMemory_brand = /*#__PURE__*/new WeakSet();
|
|
125108
|
+
class client_KVStorageProviderMemory extends client_KVStorageProviderBase {
|
|
125109
|
+
constructor() {
|
|
125110
|
+
super();
|
|
125111
|
+
client_kv_memory_classPrivateMethodInitSpec(this, client_KVStorageProviderMemory_brand);
|
|
125112
|
+
client_kv_memory_classPrivateFieldInitSpec(this, client_db, void 0);
|
|
125113
|
+
client_kv_memory_classPrivateFieldSet(client_db, this, {});
|
|
125137
125114
|
}
|
|
125138
|
-
async
|
|
125139
|
-
|
|
125140
|
-
|
|
125115
|
+
async set(arena, key, value, options) {
|
|
125116
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, arena);
|
|
125117
|
+
if (value !== undefined) {
|
|
125118
|
+
if (options !== null && options !== void 0 && options.exclusiveCreate) {
|
|
125119
|
+
if (storeArena[key] !== undefined) {
|
|
125120
|
+
throw new Error('unable to exclusively create this item, already exists');
|
|
125121
|
+
}
|
|
125122
|
+
}
|
|
125141
125123
|
}
|
|
125142
|
-
|
|
125143
|
-
|
|
125124
|
+
let expiry;
|
|
125125
|
+
if ((options === null || options === void 0 ? void 0 : options.ttl) !== undefined) {
|
|
125126
|
+
expiry = Date.now() + options.ttl;
|
|
125144
125127
|
}
|
|
125145
|
-
if (
|
|
125146
|
-
|
|
125128
|
+
if (value === undefined || value === null) {
|
|
125129
|
+
delete storeArena[key];
|
|
125130
|
+
return;
|
|
125147
125131
|
}
|
|
125148
|
-
|
|
125149
|
-
|
|
125150
|
-
|
|
125151
|
-
|
|
125152
|
-
|
|
125132
|
+
storeArena[key] = {
|
|
125133
|
+
value,
|
|
125134
|
+
expiry
|
|
125135
|
+
};
|
|
125136
|
+
}
|
|
125137
|
+
async get(arena, key) {
|
|
125138
|
+
if (arena === null) {
|
|
125139
|
+
arena = client_nullArena;
|
|
125140
|
+
}
|
|
125141
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, arena);
|
|
125142
|
+
if (!storeArena[key]) {
|
|
125143
|
+
return undefined;
|
|
125144
|
+
}
|
|
125145
|
+
const {
|
|
125146
|
+
expiry,
|
|
125147
|
+
value
|
|
125148
|
+
} = storeArena[key];
|
|
125149
|
+
if (expiry !== undefined) {
|
|
125150
|
+
if (expiry < Date.now()) {
|
|
125151
|
+
delete storeArena[key];
|
|
125152
|
+
return undefined;
|
|
125153
125153
|
}
|
|
125154
|
-
|
|
125155
|
-
|
|
125154
|
+
}
|
|
125155
|
+
const retval = client_deserialize(value);
|
|
125156
|
+
return retval;
|
|
125157
|
+
}
|
|
125158
|
+
async getAll(arena) {
|
|
125159
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, arena);
|
|
125160
|
+
const retval = {};
|
|
125161
|
+
for (const key in storeArena) {
|
|
125162
|
+
const value = await this.get(arena, key);
|
|
125163
|
+
if (value === undefined) {
|
|
125164
|
+
continue;
|
|
125156
125165
|
}
|
|
125166
|
+
retval[key] = value;
|
|
125157
125167
|
}
|
|
125158
|
-
|
|
125159
|
-
|
|
125160
|
-
|
|
125161
|
-
|
|
125162
|
-
|
|
125163
|
-
|
|
125164
|
-
|
|
125165
|
-
|
|
125166
|
-
|
|
125167
|
-
|
|
125168
|
-
|
|
125169
|
-
|
|
125170
|
-
|
|
125171
|
-
let blockCount = blocks.length;
|
|
125172
|
-
if ((possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.purpose) === client_BlockPurpose.FEE) {
|
|
125173
|
-
hasFeeBlock = true;
|
|
125174
|
-
blockCount--;
|
|
125175
|
-
}
|
|
125176
|
-
const requiredFees = new Map();
|
|
125177
|
-
for (const checkVote of otherVotes) {
|
|
125178
|
-
if (checkVote.quote === true) {
|
|
125179
|
-
throw new client_ledger('LEDGER_PERM_VOTE_WITH_QUOTE', 'Cannot request permanent votes with quotes');
|
|
125180
|
-
}
|
|
125181
|
-
if (seenVoteUIDs.has(checkVote.$id)) {
|
|
125182
|
-
throw new client_ledger('LEDGER_DUPLICATE_VOTE_FOUND', 'Duplicate vote UID found');
|
|
125183
|
-
}
|
|
125184
|
-
if (seenVoteIssuers.has(checkVote.issuer)) {
|
|
125185
|
-
throw new client_ledger('LEDGER_DUPLICATE_VOTE_ISSUER_FOUND', 'Multiple votes found from same issuer');
|
|
125186
|
-
}
|
|
125187
|
-
seenVoteIssuers.add(checkVote.issuer);
|
|
125188
|
-
seenVoteUIDs.add(checkVote.$id);
|
|
125189
|
-
if (checkVote.fee !== undefined) {
|
|
125190
|
-
requiredFees.set(checkVote.issuer, checkVote.fee);
|
|
125191
|
-
}
|
|
125192
|
-
if (checkVote.$permanent) {
|
|
125193
|
-
throw new client_ledger('LEDGER_CANNOT_EXCHANGE_PERM_VOTE', 'Asked to exchange a permanent vote for a permanent vote');
|
|
125194
|
-
}
|
|
125195
|
-
let blocksDifferFromVoteBlocks = checkVote.blocks.length !== blockCount;
|
|
125196
|
-
|
|
125197
|
-
/* If they do not differ from length alone, compare block hashes */
|
|
125198
|
-
if (!blocksDifferFromVoteBlocks) {
|
|
125199
|
-
for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
|
|
125200
|
-
if (!blocks[blockIndex].hash.compareHexString(checkVote.blocks[blockIndex])) {
|
|
125201
|
-
blocksDifferFromVoteBlocks = true;
|
|
125202
|
-
break;
|
|
125203
|
-
}
|
|
125204
|
-
}
|
|
125205
|
-
}
|
|
125206
|
-
if (blocksDifferFromVoteBlocks) {
|
|
125207
|
-
throw new client_ledger('LEDGER_BLOCKS_DIFFER_FROM_VOTED_ON', 'Asked to exchange different number of blocks for a permanent vote');
|
|
125208
|
-
}
|
|
125209
|
-
if (checkVote.issuer.comparePublicKey(ledgerPubKey)) {
|
|
125210
|
-
foundOurVote = true;
|
|
125211
|
-
}
|
|
125212
|
-
}
|
|
125213
|
-
if (requiredFees.size > 0) {
|
|
125214
|
-
if (!hasFeeBlock) {
|
|
125215
|
-
throw new client_ledger('LEDGER_MISSING_REQUIRED_FEE_BLOCK', 'Missing fee block but votes require it');
|
|
125216
|
-
}
|
|
125217
|
-
if (requiredFees.size !== (possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.operations.length)) {
|
|
125218
|
-
throw new client_ledger('LEDGER_REQUIRED_FEE_MISMATCH', 'Fee Block Operations do not match required fees');
|
|
125219
|
-
}
|
|
125220
|
-
}
|
|
125221
|
-
|
|
125222
|
-
// Verify that all required fees have been included in the fee block
|
|
125223
|
-
for (const [issuer, fee] of requiredFees) {
|
|
125224
|
-
const foundFee = possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.operations.find(operation => {
|
|
125225
|
-
var _fee$payTo, _fee$token;
|
|
125226
|
-
const expectedPayTo = (_fee$payTo = fee.payTo) !== null && _fee$payTo !== void 0 ? _fee$payTo : issuer;
|
|
125227
|
-
const expectedToken = (_fee$token = fee.token) !== null && _fee$token !== void 0 ? _fee$token : client_ledger_classPrivateFieldGet(src_client_ledger, this).baseToken;
|
|
125228
|
-
if (operation.type === client_OperationType.SEND && operation.to.comparePublicKey(expectedPayTo)) {
|
|
125229
|
-
if (operation.amount !== fee.amount) {
|
|
125230
|
-
throw new client_ledger('LEDGER_FEE_AMOUNT_MISMATCH', `Fee Amount Mismatch, found: ${operation.amount} expected: ${fee.amount}`);
|
|
125231
|
-
}
|
|
125232
|
-
if (!operation.token.comparePublicKey(expectedToken)) {
|
|
125233
|
-
throw new client_ledger('LEDGER_FEE_TOKEN_MISMATCH', `Fee Token Mismatch, found: ${operation.token.publicKeyString.get()} expected: ${expectedToken.publicKeyString.get()}`);
|
|
125234
|
-
}
|
|
125235
|
-
return true;
|
|
125236
|
-
}
|
|
125237
|
-
return false;
|
|
125238
|
-
});
|
|
125239
|
-
if (foundFee === undefined) {
|
|
125240
|
-
var _fee$payTo$publicKeyS, _fee$payTo2;
|
|
125241
|
-
throw new client_ledger('LEDGER_FEE_MISSING', `Missing Required Fee for ${(_fee$payTo$publicKeyS = (_fee$payTo2 = fee.payTo) === null || _fee$payTo2 === void 0 ? void 0 : _fee$payTo2.publicKeyString.get()) !== null && _fee$payTo$publicKeyS !== void 0 ? _fee$payTo$publicKeyS : issuer.publicKeyString.get()}`);
|
|
125242
|
-
}
|
|
125243
|
-
}
|
|
125244
|
-
if (!foundOurVote) {
|
|
125245
|
-
throw new client_ledger('LEDGER_NO_PERM_WITHOUT_SELF_TEMP', 'Asked to give a permanent vote without a temporary vote from us');
|
|
125246
|
-
}
|
|
125168
|
+
return retval;
|
|
125169
|
+
}
|
|
125170
|
+
async list(arena) {
|
|
125171
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, arena);
|
|
125172
|
+
return Object.keys(storeArena);
|
|
125173
|
+
}
|
|
125174
|
+
async incr(arena, key, change) {
|
|
125175
|
+
var _previous$value;
|
|
125176
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, arena);
|
|
125177
|
+
const previous = storeArena[key];
|
|
125178
|
+
let previousValue = (_previous$value = previous === null || previous === void 0 ? void 0 : previous.value) !== null && _previous$value !== void 0 ? _previous$value : 0;
|
|
125179
|
+
if (typeof previousValue !== 'number') {
|
|
125180
|
+
throw new Error('May not increment non-number');
|
|
125247
125181
|
}
|
|
125248
|
-
|
|
125249
|
-
|
|
125250
|
-
|
|
125251
|
-
|
|
125252
|
-
|
|
125253
|
-
|
|
125254
|
-
if (!expectedBlock.$opening) {
|
|
125255
|
-
throw new client_ledger('LEDGER_NOT_OPENING', 'Cannot vote on non-opening block for an empty account');
|
|
125256
|
-
}
|
|
125257
|
-
continue;
|
|
125258
|
-
}
|
|
125259
|
-
if (expectedBlock.$opening) {
|
|
125260
|
-
throw new client_ledger('LEDGER_NOT_EMPTY', 'Cannot vote on opening block for a non-empty account');
|
|
125261
|
-
}
|
|
125262
|
-
if (expectedBlock.previous.toString() !== accountHead.toString()) {
|
|
125263
|
-
throw new client_ledger('LEDGER_NOT_SUCCESSOR', 'The block is not the successor to the account head block');
|
|
125182
|
+
let newExpiry;
|
|
125183
|
+
if ((previous === null || previous === void 0 ? void 0 : previous.expiry) !== undefined) {
|
|
125184
|
+
if (previous.expiry < Date.now()) {
|
|
125185
|
+
previousValue = 0;
|
|
125186
|
+
} else {
|
|
125187
|
+
newExpiry = previous.expiry;
|
|
125264
125188
|
}
|
|
125265
125189
|
}
|
|
125266
|
-
|
|
125267
|
-
|
|
125268
|
-
|
|
125269
|
-
|
|
125270
|
-
|
|
125271
|
-
|
|
125272
|
-
|
|
125273
|
-
|
|
125274
|
-
|
|
125275
|
-
|
|
125276
|
-
|
|
125277
|
-
|
|
125278
|
-
|
|
125279
|
-
|
|
125280
|
-
|
|
125281
|
-
|
|
125282
|
-
|
|
125283
|
-
let mayReplace = false;
|
|
125284
|
-
if (previousVotes.length === 1 && otherVotes !== undefined && otherVotes.length !== 0) {
|
|
125285
|
-
const ourVote = previousVotes[0];
|
|
125286
|
-
mayReplace = !ourVote.$permanent && ourVote.issuer.comparePublicKey(ledgerPubKey);
|
|
125287
|
-
}
|
|
125288
|
-
if (!mayReplace) {
|
|
125289
|
-
throw new client_ledger('LEDGER_SUCCESSOR_VOTE_EXISTS', `We cannot vote for this block (hash=${block.hash.toString()}), we have an existing vote for a successor (previous votes = ${JSON.stringify(client_toJSONSerializable(previousVotes))})`);
|
|
125290
|
-
}
|
|
125291
|
-
}
|
|
125190
|
+
const newVal = previousValue + change;
|
|
125191
|
+
storeArena[key] = {
|
|
125192
|
+
value: newVal,
|
|
125193
|
+
expiry: newExpiry
|
|
125194
|
+
};
|
|
125195
|
+
return BigInt(newVal);
|
|
125196
|
+
}
|
|
125197
|
+
async xor(arena, key, change) {
|
|
125198
|
+
await super.xor(arena, key, change);
|
|
125199
|
+
const storeArena = client_kv_memory_assertClassBrand(client_KVStorageProviderMemory_brand, this, client_getArena).call(this, client_nullArena);
|
|
125200
|
+
const previous = storeArena[key];
|
|
125201
|
+
const value = previous === null || previous === void 0 ? void 0 : previous.value;
|
|
125202
|
+
if (value === undefined) {
|
|
125203
|
+
storeArena[key] = {
|
|
125204
|
+
value: change
|
|
125205
|
+
};
|
|
125206
|
+
return;
|
|
125292
125207
|
}
|
|
125293
|
-
|
|
125294
|
-
|
|
125295
|
-
* If no other votes have been supplied, validate that the blocks are valid, and issue a short vote
|
|
125296
|
-
*/
|
|
125297
|
-
if (otherVotes === undefined) {
|
|
125298
|
-
const vote = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_voteOrQuoteWithFees).call(this, blocks, 'VOTE', quote);
|
|
125299
|
-
const blocksAndVote = src_client_VoteStaple.fromVotesAndBlocks([vote], blocks);
|
|
125300
|
-
await client_ledger_classPrivateFieldGet(client_ledger_storage, this).addPendingVote(transaction, blocksAndVote);
|
|
125301
|
-
return vote;
|
|
125208
|
+
if (!src_client_BufferStorage.isInstance(value) || previous.expiry !== undefined) {
|
|
125209
|
+
throw new Error('May only use XOR on keys containing BufferStorage without expiry');
|
|
125302
125210
|
}
|
|
125211
|
+
const valueBigInt = value.toBigInt();
|
|
125212
|
+
const changeBigInt = change.toBigInt();
|
|
125213
|
+
const valueLength = Math.max(value.length, change.length);
|
|
125214
|
+
const newValue = valueBigInt ^ changeBigInt;
|
|
125215
|
+
storeArena[key] = {
|
|
125216
|
+
value: new src_client_BufferStorage(newValue, valueLength)
|
|
125217
|
+
};
|
|
125218
|
+
}
|
|
125219
|
+
}
|
|
125220
|
+
function client_getArena(arena) {
|
|
125221
|
+
if (client_kv_memory_classPrivateFieldGet(client_db, this)[arena] === undefined) {
|
|
125222
|
+
client_kv_memory_classPrivateFieldGet(client_db, this)[arena] = {};
|
|
125223
|
+
}
|
|
125224
|
+
return client_kv_memory_classPrivateFieldGet(client_db, this)[arena];
|
|
125225
|
+
}
|
|
125226
|
+
/* harmony default export */ const client_kv_memory = (client_KVStorageProviderMemory);
|
|
125227
|
+
;// ./src/lib/stats.ts
|
|
125228
|
+
function client_stats_classPrivateFieldInitSpec(e, t, a) { client_stats_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
125229
|
+
function client_stats_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
125230
|
+
function client_stats_classPrivateFieldGet(s, a) { return s.get(client_stats_assertClassBrand(s, a)); }
|
|
125231
|
+
function client_stats_classPrivateFieldSet(s, a, r) { return s.set(client_stats_assertClassBrand(s, a), r), r; }
|
|
125232
|
+
function client_stats_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
125233
|
+
function client_stats_defineProperty(e, r, t) { return (r = client_stats_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
125234
|
+
function client_stats_toPropertyKey(t) { var i = client_stats_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
125235
|
+
function client_stats_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
125303
125236
|
|
|
125304
|
-
/**
|
|
125305
|
-
* Validate the votes are sufficient weight and grant
|
|
125306
|
-
* our permanent vote
|
|
125307
|
-
*/
|
|
125308
|
-
const votesSufficient = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateVotingWeight).call(this, otherVotes);
|
|
125309
|
-
if (votesSufficient !== true) {
|
|
125310
|
-
throw new client_ledger('LEDGER_INSUFFICIENT_VOTING_WEIGHT', 'Unable to create a vote from these votes, they do not represent enough voting power');
|
|
125311
|
-
}
|
|
125312
125237
|
|
|
125313
|
-
/**
|
|
125314
|
-
* Serial number
|
|
125315
|
-
*/
|
|
125316
|
-
const serial = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getNextSerialNumber(client_ledger_classPrivateFieldGet(client_transaction, this));
|
|
125317
|
-
const wipVote = new src_client_VoteBuilder(privateKey);
|
|
125318
|
-
for (const block of blocks) {
|
|
125319
|
-
wipVote.addBlock(block);
|
|
125320
|
-
}
|
|
125321
|
-
const vote = await wipVote.seal(serial, null);
|
|
125322
|
-
const blocksAndVote = src_client_VoteStaple.fromVotesAndBlocks([vote], blocks);
|
|
125323
125238
|
|
|
125324
|
-
|
|
125325
|
-
|
|
125326
|
-
|
|
125327
|
-
|
|
125328
|
-
|
|
125329
|
-
|
|
125239
|
+
/**
|
|
125240
|
+
* Size of the XOR buffer objects -- we use them for block hashes so they
|
|
125241
|
+
* should be the same size as a block hash
|
|
125242
|
+
*/
|
|
125243
|
+
const client_XOR_BUFFER_SIZE = client_HashFunctionLength;
|
|
125244
|
+
const client_durationRanges = {
|
|
125245
|
+
'-1ms': [-1, -1],
|
|
125246
|
+
'0ms': [0, 0],
|
|
125247
|
+
'10ms': [1, 10],
|
|
125248
|
+
'100ms': [11, 100],
|
|
125249
|
+
'200ms': [101, 200],
|
|
125250
|
+
'300ms': [201, 300],
|
|
125251
|
+
'400ms': [301, 400],
|
|
125252
|
+
'500ms': [401, 500],
|
|
125253
|
+
'600ms': [501, 600],
|
|
125254
|
+
'700ms': [601, 700],
|
|
125255
|
+
'800ms': [701, 800],
|
|
125256
|
+
'900ms': [801, 900],
|
|
125257
|
+
'1000ms': [901, 1000],
|
|
125258
|
+
'1500ms': [1001, 1500],
|
|
125259
|
+
'2000ms': [1501, 2000],
|
|
125260
|
+
'5000ms': [2001, 5000],
|
|
125261
|
+
'10000ms': [5001, 10000],
|
|
125262
|
+
'100000ms': [10001, 100000],
|
|
125263
|
+
'ExtraLong': [100000, Number.MAX_SAFE_INTEGER]
|
|
125264
|
+
};
|
|
125265
|
+
class client_stats_StatsPending {
|
|
125266
|
+
constructor() {
|
|
125267
|
+
client_stats_defineProperty(this, "localDBIncr", {});
|
|
125268
|
+
client_stats_defineProperty(this, "localDBXOR", {});
|
|
125269
|
+
}
|
|
125270
|
+
consume() {
|
|
125271
|
+
const incrChanges = this.localDBIncr;
|
|
125272
|
+
this.localDBIncr = {};
|
|
125273
|
+
const xorChanges = this.localDBXOR;
|
|
125274
|
+
this.localDBXOR = {};
|
|
125275
|
+
return {
|
|
125276
|
+
incrChanges,
|
|
125277
|
+
xorChanges
|
|
125278
|
+
};
|
|
125330
125279
|
}
|
|
125331
|
-
|
|
125332
|
-
|
|
125333
|
-
|
|
125334
|
-
return quote;
|
|
125280
|
+
compoundKey(arena, key) {
|
|
125281
|
+
const compoundKey = [arena, key].join('|');
|
|
125282
|
+
return compoundKey;
|
|
125335
125283
|
}
|
|
125336
|
-
|
|
125337
|
-
|
|
125338
|
-
|
|
125339
|
-
|
|
125340
|
-
|
|
125341
|
-
|
|
125342
|
-
|
|
125343
|
-
|
|
125344
|
-
|
|
125345
|
-
|
|
125346
|
-
|
|
125347
|
-
|
|
125348
|
-
|
|
125349
|
-
|
|
125350
|
-
|
|
125351
|
-
|
|
125284
|
+
incrCompoundKey(compoundKey, change) {
|
|
125285
|
+
if (this.localDBIncr[compoundKey] === undefined) {
|
|
125286
|
+
this.localDBIncr[compoundKey] = 0;
|
|
125287
|
+
}
|
|
125288
|
+
this.localDBIncr[compoundKey] += change;
|
|
125289
|
+
}
|
|
125290
|
+
incr(arena, key) {
|
|
125291
|
+
let change = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
125292
|
+
const compoundKey = this.compoundKey(arena, key);
|
|
125293
|
+
this.incrCompoundKey(compoundKey, change);
|
|
125294
|
+
}
|
|
125295
|
+
xor(key, change) {
|
|
125296
|
+
const changeValue = typeof change === 'bigint' ? change : change.toBigInt();
|
|
125297
|
+
const existingValue = this.localDBXOR[key];
|
|
125298
|
+
if (existingValue === undefined) {
|
|
125299
|
+
this.localDBXOR[key] = changeValue;
|
|
125300
|
+
return;
|
|
125352
125301
|
}
|
|
125302
|
+
this.localDBXOR[key] ^= changeValue;
|
|
125303
|
+
}
|
|
125304
|
+
merge(pending) {
|
|
125353
125305
|
const {
|
|
125354
|
-
|
|
125355
|
-
|
|
125356
|
-
} =
|
|
125357
|
-
|
|
125358
|
-
|
|
125306
|
+
incrChanges,
|
|
125307
|
+
xorChanges
|
|
125308
|
+
} = pending.consume();
|
|
125309
|
+
// Merge incr changes
|
|
125310
|
+
for (const [key, value] of Object.entries(incrChanges)) {
|
|
125311
|
+
this.incrCompoundKey(key, value);
|
|
125359
125312
|
}
|
|
125360
|
-
|
|
125361
|
-
|
|
125362
|
-
|
|
125363
|
-
|
|
125364
|
-
if (block.subnet !== client_ledger_classPrivateFieldGet(client_subnet, this)) {
|
|
125365
|
-
throw new Error('Cannot process block for a different subnet');
|
|
125366
|
-
}
|
|
125313
|
+
|
|
125314
|
+
// Merge xor changes
|
|
125315
|
+
for (const [key, value] of Object.entries(xorChanges)) {
|
|
125316
|
+
this.xor(key, value);
|
|
125367
125317
|
}
|
|
125368
|
-
|
|
125369
|
-
|
|
125370
|
-
|
|
125371
|
-
|
|
125318
|
+
}
|
|
125319
|
+
}
|
|
125320
|
+
var client_syncPromise = /*#__PURE__*/new WeakMap();
|
|
125321
|
+
var client_kv = /*#__PURE__*/new WeakMap();
|
|
125322
|
+
class client_Stats extends client_stats_StatsPending {
|
|
125323
|
+
constructor(config) {
|
|
125324
|
+
super();
|
|
125325
|
+
client_stats_classPrivateFieldInitSpec(this, client_syncPromise, void 0);
|
|
125326
|
+
client_stats_classPrivateFieldInitSpec(this, client_kv, void 0);
|
|
125327
|
+
let kv = config.kv;
|
|
125328
|
+
if (kv === null) {
|
|
125329
|
+
kv = new client_kv_memory();
|
|
125372
125330
|
}
|
|
125373
|
-
|
|
125374
|
-
|
|
125375
|
-
|
|
125376
|
-
|
|
125331
|
+
client_stats_classPrivateFieldSet(client_kv, this, kv);
|
|
125332
|
+
}
|
|
125333
|
+
|
|
125334
|
+
// Return all keys from durationRanges
|
|
125335
|
+
static durationBreakdownList() {
|
|
125336
|
+
// We know the keys are all valid to the type, but typescript does not know this
|
|
125337
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
125338
|
+
return Object.keys(client_durationRanges);
|
|
125339
|
+
}
|
|
125340
|
+
static assertDurationBreakdown(duration) {
|
|
125341
|
+
if (!(duration in client_durationRanges)) {
|
|
125342
|
+
throw new Error(`Invalid duration: ${duration}`);
|
|
125377
125343
|
}
|
|
125378
|
-
|
|
125379
|
-
|
|
125380
|
-
|
|
125381
|
-
|
|
125382
|
-
|
|
125383
|
-
|
|
125384
|
-
|
|
125385
|
-
|
|
125386
|
-
|
|
125387
|
-
|
|
125388
|
-
|
|
125389
|
-
|
|
125390
|
-
if (ourNode) {
|
|
125391
|
-
for (const staple of voteStaples) {
|
|
125392
|
-
for (const block of staple.blocks) {
|
|
125393
|
-
ourNode.stats.xor('ledgerChecksum', block.hash);
|
|
125394
|
-
}
|
|
125344
|
+
}
|
|
125345
|
+
// Get duration key for specific number
|
|
125346
|
+
static durationBreakdown(duration) {
|
|
125347
|
+
// Loop through ranges and select key with range that fits around duration
|
|
125348
|
+
|
|
125349
|
+
if (duration < 0) {
|
|
125350
|
+
duration = 0;
|
|
125351
|
+
}
|
|
125352
|
+
for (const name of this.durationBreakdownList()) {
|
|
125353
|
+
const [min, max] = client_durationRanges[name];
|
|
125354
|
+
if (duration >= min && (max === undefined || duration <= max)) {
|
|
125355
|
+
return name;
|
|
125395
125356
|
}
|
|
125396
125357
|
}
|
|
125397
|
-
|
|
125398
|
-
return voteStaples;
|
|
125358
|
+
throw new Error(`Time frame not found for duration: ${duration}`);
|
|
125399
125359
|
}
|
|
125400
|
-
|
|
125401
|
-
const
|
|
125402
|
-
const
|
|
125403
|
-
|
|
125404
|
-
|
|
125360
|
+
static placeholderTimingData() {
|
|
125361
|
+
const ret = {};
|
|
125362
|
+
for (const key of this.durationBreakdownList()) {
|
|
125363
|
+
ret[key] = {
|
|
125364
|
+
count: -1,
|
|
125365
|
+
range: client_stats_assertClassBrand(client_Stats, this, client_getDurationRange).call(this, key)
|
|
125366
|
+
};
|
|
125405
125367
|
}
|
|
125406
|
-
|
|
125368
|
+
|
|
125369
|
+
// We know this fits TimeStats because we just created it with all of the keys
|
|
125370
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
125371
|
+
return ret;
|
|
125407
125372
|
}
|
|
125408
|
-
async
|
|
125409
|
-
|
|
125410
|
-
const
|
|
125411
|
-
|
|
125412
|
-
|
|
125413
|
-
|
|
125414
|
-
|
|
125415
|
-
if (balance < 0n) {
|
|
125416
|
-
throw new Error(`internal error: Account with negative balance: ${account.publicKeyString.get()}/${token.publicKeyString.get()}: ${balance}`);
|
|
125417
|
-
}
|
|
125373
|
+
async getXor(key) {
|
|
125374
|
+
await client_stats_classPrivateFieldGet(client_syncPromise, this);
|
|
125375
|
+
const bufferKey = `@buffer:${key}`;
|
|
125376
|
+
const baseString = await client_stats_classPrivateFieldGet(client_kv, this).get(null, bufferKey);
|
|
125377
|
+
let base = 0n;
|
|
125378
|
+
if (baseString !== undefined) {
|
|
125379
|
+
base = BigInt(`0x${baseString}`);
|
|
125418
125380
|
}
|
|
125419
|
-
|
|
125420
|
-
|
|
125421
|
-
|
|
125422
|
-
|
|
125423
|
-
|
|
125381
|
+
let local = 0n;
|
|
125382
|
+
if (this.localDBXOR[key] !== undefined) {
|
|
125383
|
+
local = this.localDBXOR[key];
|
|
125384
|
+
}
|
|
125385
|
+
const computed = base ^ local;
|
|
125386
|
+
const retval = new src_client_BufferStorage(computed, client_XOR_BUFFER_SIZE);
|
|
125387
|
+
return retval;
|
|
125424
125388
|
}
|
|
125425
|
-
|
|
125426
|
-
|
|
125427
|
-
|
|
125389
|
+
|
|
125390
|
+
// Calculate key and increment for specific duration/category
|
|
125391
|
+
addTimingPoint(arena, category, duration) {
|
|
125392
|
+
let returnOnly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
125393
|
+
const breakdown = client_Stats.durationBreakdown(duration);
|
|
125394
|
+
const params = [arena, `${category}@${breakdown}`, 1];
|
|
125395
|
+
if (returnOnly !== true) {
|
|
125396
|
+
this.incr(...params);
|
|
125397
|
+
}
|
|
125398
|
+
return params;
|
|
125428
125399
|
}
|
|
125429
|
-
|
|
125430
|
-
|
|
125431
|
-
const
|
|
125432
|
-
|
|
125400
|
+
addRequestTiming(arena, timing) {
|
|
125401
|
+
let returnOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
125402
|
+
const retval = [];
|
|
125403
|
+
for (const sectionInfo of Object.values(timing.getAllTiming())) {
|
|
125404
|
+
const duration = sectionInfo.duration;
|
|
125405
|
+
const name = sectionInfo.name;
|
|
125406
|
+
retval.push(this.addTimingPoint(arena, name, duration, returnOnly));
|
|
125407
|
+
}
|
|
125408
|
+
return retval;
|
|
125433
125409
|
}
|
|
125434
|
-
async
|
|
125435
|
-
|
|
125436
|
-
const
|
|
125437
|
-
|
|
125410
|
+
async get(arena, key) {
|
|
125411
|
+
await client_stats_classPrivateFieldGet(client_syncPromise, this);
|
|
125412
|
+
const compoundKey = this.compoundKey(arena, key);
|
|
125413
|
+
let base = await client_stats_classPrivateFieldGet(client_kv, this).get('stats', compoundKey);
|
|
125414
|
+
if (base === undefined) {
|
|
125415
|
+
base = 0;
|
|
125416
|
+
}
|
|
125417
|
+
if (typeof base === 'string') {
|
|
125418
|
+
base = Number(base);
|
|
125419
|
+
}
|
|
125420
|
+
if (typeof base !== 'number' || isNaN(base)) {
|
|
125421
|
+
throw new Error('internal error: corrupt data in stats table');
|
|
125422
|
+
}
|
|
125423
|
+
let local = 0;
|
|
125424
|
+
if (this.localDBIncr[compoundKey] !== undefined) {
|
|
125425
|
+
local = this.localDBIncr[compoundKey];
|
|
125426
|
+
}
|
|
125427
|
+
return base + local;
|
|
125438
125428
|
}
|
|
125439
|
-
async votingPower(rep) {
|
|
125440
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125441
|
-
const weight = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction, rep);
|
|
125442
125429
|
|
|
125443
|
-
|
|
125444
|
-
|
|
125445
|
-
|
|
125446
|
-
|
|
125447
|
-
|
|
125448
|
-
|
|
125449
|
-
|
|
125430
|
+
// Get all timing data from specific arena/category
|
|
125431
|
+
async getTimingData(arena, category) {
|
|
125432
|
+
const retval = client_Stats.placeholderTimingData();
|
|
125433
|
+
const keys = Object.keys(retval);
|
|
125434
|
+
client_assertDurationBreakdowns.call(client_Stats, keys);
|
|
125435
|
+
await Promise.all(keys.map(async breakdown => {
|
|
125436
|
+
const key = `${category}@${breakdown}`;
|
|
125437
|
+
const range = client_getDurationRange.call(client_Stats, breakdown);
|
|
125438
|
+
let count = -1;
|
|
125439
|
+
try {
|
|
125440
|
+
count = await this.get(arena, key);
|
|
125441
|
+
} catch (_ignored_error) {
|
|
125442
|
+
/* Errors fetching single stat are ignored */
|
|
125443
|
+
} finally {
|
|
125444
|
+
retval[breakdown] = {
|
|
125445
|
+
count,
|
|
125446
|
+
range
|
|
125447
|
+
};
|
|
125448
|
+
}
|
|
125449
|
+
}));
|
|
125450
125450
|
return retval;
|
|
125451
125451
|
}
|
|
125452
|
-
async
|
|
125453
|
-
|
|
125454
|
-
|
|
125455
|
-
|
|
125456
|
-
|
|
125457
|
-
|
|
125452
|
+
async sync() {
|
|
125453
|
+
const {
|
|
125454
|
+
incrChanges,
|
|
125455
|
+
xorChanges
|
|
125456
|
+
} = this.consume();
|
|
125457
|
+
await client_stats_classPrivateFieldGet(client_syncPromise, this);
|
|
125458
|
+
client_stats_classPrivateFieldSet(client_syncPromise, this, (async () => {
|
|
125459
|
+
const updatePromises = [];
|
|
125460
|
+
for (const [key, value] of Object.entries(incrChanges)) {
|
|
125461
|
+
if (value === undefined) {
|
|
125462
|
+
continue;
|
|
125463
|
+
}
|
|
125464
|
+
updatePromises.push(client_stats_classPrivateFieldGet(client_kv, this).incr('stats', key, value));
|
|
125465
|
+
}
|
|
125466
|
+
for (const [key, value] of Object.entries(xorChanges)) {
|
|
125467
|
+
if (value === undefined) {
|
|
125468
|
+
continue;
|
|
125469
|
+
}
|
|
125470
|
+
const valueBuffer = new src_client_BufferStorage(value, client_XOR_BUFFER_SIZE);
|
|
125471
|
+
const bufferKey = `@buffer:${key}`;
|
|
125472
|
+
updatePromises.push(client_stats_classPrivateFieldGet(client_kv, this).xor(null, bufferKey, valueBuffer));
|
|
125473
|
+
}
|
|
125474
|
+
await Promise.all(updatePromises);
|
|
125475
|
+
})());
|
|
125476
|
+
await client_stats_classPrivateFieldGet(client_syncPromise, this);
|
|
125477
|
+
client_stats_classPrivateFieldSet(client_syncPromise, this, undefined);
|
|
125458
125478
|
}
|
|
125459
|
-
|
|
125460
|
-
|
|
125461
|
-
|
|
125462
|
-
|
|
125479
|
+
}
|
|
125480
|
+
function client_assertDurationBreakdowns(durations) {
|
|
125481
|
+
for (const duration of durations) {
|
|
125482
|
+
this.assertDurationBreakdown(duration);
|
|
125463
125483
|
}
|
|
125464
|
-
|
|
125465
|
-
|
|
125466
|
-
|
|
125467
|
-
|
|
125484
|
+
}
|
|
125485
|
+
function client_getDurationRange(duration) {
|
|
125486
|
+
this.assertDurationBreakdown(duration);
|
|
125487
|
+
const range = client_durationRanges[duration];
|
|
125488
|
+
if (!range) {
|
|
125489
|
+
throw new Error(`Could not get range for invalid duration: ${duration}, got range ${range}`);
|
|
125468
125490
|
}
|
|
125469
|
-
|
|
125470
|
-
|
|
125471
|
-
|
|
125472
|
-
|
|
125491
|
+
|
|
125492
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
125493
|
+
return range;
|
|
125494
|
+
}
|
|
125495
|
+
/* harmony default export */ const client_stats = (client_Stats);
|
|
125496
|
+
;// ./src/lib/ledger/index.ts
|
|
125497
|
+
var client_Ledger;
|
|
125498
|
+
function client_usingCtx2() { var r = "function" == typeof SuppressedError ? SuppressedError : function (r, e) { var n = Error(); return n.name = "SuppressedError", n.error = r, n.suppressed = e, n; }, e = {}, n = []; function using(r, e) { if (null != e) { if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined."); if (r) var o = e[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; if (void 0 === o && (o = e[Symbol.dispose || Symbol.for("Symbol.dispose")], r)) var t = o; if ("function" != typeof o) throw new TypeError("Object is not disposable."); t && (o = function () { try { t.call(e); } catch (r) { return Promise.reject(r); } }), n.push({ v: e, d: o, a: r }); } else r && n.push({ d: e, a: r }); return e; } return { e: e, u: using.bind(null, !1), a: using.bind(null, !0), d: function () { var o, t = this.e, s = 0; function next() { for (; o = n.pop();) try { if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next); if (o.d) { var r = o.d.call(o.v); if (o.a) return s |= 2, Promise.resolve(r).then(next, err); } else s |= 1; } catch (r) { return err(r); } if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve(); if (t !== e) throw t; } function err(n) { return t = t !== e ? new r(n, t) : n, next(); } return next(); } }; }
|
|
125499
|
+
function client_lib_ledger_defineProperty(e, r, t) { return (r = client_lib_ledger_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
125500
|
+
function client_lib_ledger_toPropertyKey(t) { var i = client_lib_ledger_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
125501
|
+
function client_lib_ledger_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
125502
|
+
function client_ledger_classPrivateMethodInitSpec(e, a) { client_ledger_checkPrivateRedeclaration(e, a), a.add(e); }
|
|
125503
|
+
function client_ledger_classPrivateFieldInitSpec(e, t, a) { client_ledger_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
125504
|
+
function client_ledger_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
125505
|
+
function client_ledger_classPrivateFieldGet(s, a) { return s.get(client_ledger_assertClassBrand(s, a)); }
|
|
125506
|
+
function client_ledger_classPrivateFieldSet(s, a, r) { return s.set(client_ledger_assertClassBrand(s, a), r), r; }
|
|
125507
|
+
function client_ledger_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
125508
|
+
|
|
125509
|
+
|
|
125510
|
+
|
|
125511
|
+
|
|
125512
|
+
|
|
125513
|
+
|
|
125514
|
+
|
|
125515
|
+
|
|
125516
|
+
|
|
125517
|
+
|
|
125518
|
+
|
|
125519
|
+
|
|
125520
|
+
|
|
125521
|
+
|
|
125522
|
+
/**
|
|
125523
|
+
* Kind of ledger
|
|
125524
|
+
*/
|
|
125525
|
+
let client_LedgerKind = /*#__PURE__*/function (LedgerKind) {
|
|
125526
|
+
LedgerKind[LedgerKind["REPRESENTATIVE"] = 0] = "REPRESENTATIVE";
|
|
125527
|
+
LedgerKind[LedgerKind["ACCOUNT"] = 1] = "ACCOUNT";
|
|
125528
|
+
return LedgerKind;
|
|
125529
|
+
}({});
|
|
125530
|
+
|
|
125531
|
+
/**
|
|
125532
|
+
* Ledger configuration
|
|
125533
|
+
*/
|
|
125534
|
+
|
|
125535
|
+
/**
|
|
125536
|
+
* Which ledger to store this data in
|
|
125537
|
+
*/
|
|
125538
|
+
|
|
125539
|
+
/**
|
|
125540
|
+
* Which ledger(s) to pull the data from
|
|
125541
|
+
*/
|
|
125542
|
+
|
|
125543
|
+
/**
|
|
125544
|
+
* A set of votes and a pointer to the next set/page
|
|
125545
|
+
*/
|
|
125546
|
+
|
|
125547
|
+
/**
|
|
125548
|
+
* Options for "getVotesAfter"
|
|
125549
|
+
*/
|
|
125550
|
+
|
|
125551
|
+
/**
|
|
125552
|
+
* Each transaction can contain the node object making the request to access things like timing information
|
|
125553
|
+
*/
|
|
125554
|
+
|
|
125555
|
+
class client_LedgerStorageTransactionBase {
|
|
125556
|
+
constructor(options) {
|
|
125557
|
+
var _options$moment, _options$readOnly;
|
|
125558
|
+
this.node = options.node;
|
|
125559
|
+
this.moment = (_options$moment = options.moment) !== null && _options$moment !== void 0 ? _options$moment : new Date();
|
|
125560
|
+
this.identifier = options.identifier;
|
|
125561
|
+
this.readOnly = (_options$readOnly = options.readOnly) !== null && _options$readOnly !== void 0 ? _options$readOnly : true;
|
|
125562
|
+
this.statsPending = new StatsPending();
|
|
125473
125563
|
}
|
|
125474
|
-
|
|
125475
|
-
|
|
125476
|
-
|
|
125477
|
-
|
|
125564
|
+
}
|
|
125565
|
+
|
|
125566
|
+
/**
|
|
125567
|
+
* Each Ledger Storage backend must implement this interface
|
|
125568
|
+
*/
|
|
125569
|
+
var client_network = /*#__PURE__*/new WeakMap();
|
|
125570
|
+
var client_subnet = /*#__PURE__*/new WeakMap();
|
|
125571
|
+
var client_kind = /*#__PURE__*/new WeakMap();
|
|
125572
|
+
var client_ledger_privateKey = /*#__PURE__*/new WeakMap();
|
|
125573
|
+
var client_computeFeeFromBlocks = /*#__PURE__*/new WeakMap();
|
|
125574
|
+
var client_ledger_storage = /*#__PURE__*/new WeakMap();
|
|
125575
|
+
var src_client_ledger = /*#__PURE__*/new WeakMap();
|
|
125576
|
+
var src_client_cache = /*#__PURE__*/new WeakMap();
|
|
125577
|
+
var client_transaction = /*#__PURE__*/new WeakMap();
|
|
125578
|
+
var client_LedgerAtomicInterface_brand = /*#__PURE__*/new WeakSet();
|
|
125579
|
+
/**
|
|
125580
|
+
* Atomic transactional interface to a storage backend
|
|
125581
|
+
*/
|
|
125582
|
+
class client_LedgerAtomicInterface {
|
|
125583
|
+
constructor(_transaction2, storage, config, ledger) {
|
|
125584
|
+
client_ledger_classPrivateMethodInitSpec(this, client_LedgerAtomicInterface_brand);
|
|
125585
|
+
client_ledger_classPrivateFieldInitSpec(this, client_network, void 0);
|
|
125586
|
+
client_ledger_classPrivateFieldInitSpec(this, client_subnet, void 0);
|
|
125587
|
+
client_ledger_classPrivateFieldInitSpec(this, client_kind, void 0);
|
|
125588
|
+
client_ledger_classPrivateFieldInitSpec(this, client_ledger_privateKey, void 0);
|
|
125589
|
+
client_ledger_classPrivateFieldInitSpec(this, client_computeFeeFromBlocks, void 0);
|
|
125590
|
+
client_ledger_classPrivateFieldInitSpec(this, client_ledger_storage, void 0);
|
|
125591
|
+
client_ledger_classPrivateFieldInitSpec(this, src_client_ledger, void 0);
|
|
125592
|
+
client_ledger_classPrivateFieldInitSpec(this, src_client_cache, void 0);
|
|
125593
|
+
client_ledger_classPrivateFieldInitSpec(this, client_transaction, void 0);
|
|
125594
|
+
client_ledger_classPrivateFieldSet(client_network, this, config.network);
|
|
125595
|
+
client_ledger_classPrivateFieldSet(client_subnet, this, config.subnet);
|
|
125596
|
+
client_ledger_classPrivateFieldSet(client_kind, this, config.kind);
|
|
125597
|
+
client_ledger_classPrivateFieldSet(client_ledger_privateKey, this, config.privateKey);
|
|
125598
|
+
client_ledger_classPrivateFieldSet(client_computeFeeFromBlocks, this, config.computeFeeFromBlocks);
|
|
125599
|
+
client_ledger_classPrivateFieldSet(src_client_ledger, this, ledger);
|
|
125600
|
+
client_ledger_classPrivateFieldSet(client_ledger_storage, this, storage);
|
|
125601
|
+
client_ledger_classPrivateFieldSet(client_transaction, this, _transaction2);
|
|
125602
|
+
|
|
125603
|
+
/**
|
|
125604
|
+
* Link the storage driver's cache to the transaction cache
|
|
125605
|
+
*/
|
|
125606
|
+
let existingCache;
|
|
125607
|
+
if ('cache' in storage && storage.cache !== undefined) {
|
|
125608
|
+
existingCache = storage.cache(_transaction2);
|
|
125609
|
+
}
|
|
125610
|
+
if (existingCache !== undefined) {
|
|
125611
|
+
client_ledger_classPrivateFieldSet(src_client_cache, this, existingCache);
|
|
125612
|
+
} else {
|
|
125613
|
+
client_ledger_classPrivateFieldSet(src_client_cache, this, new client_cache());
|
|
125614
|
+
}
|
|
125478
125615
|
}
|
|
125479
|
-
async
|
|
125616
|
+
async commit() {
|
|
125617
|
+
var _classPrivateFieldGet2;
|
|
125480
125618
|
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125481
|
-
|
|
125482
|
-
|
|
125619
|
+
client_ledger_classPrivateFieldSet(client_transaction, this, null);
|
|
125620
|
+
await client_ledger_classPrivateFieldGet(client_ledger_storage, this).commitTransaction(transaction);
|
|
125621
|
+
(_classPrivateFieldGet2 = client_ledger_classPrivateFieldGet(src_client_ledger, this).node) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.stats.merge(transaction.statsPending);
|
|
125483
125622
|
}
|
|
125484
|
-
async
|
|
125485
|
-
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125623
|
+
async abort() {
|
|
125486
125624
|
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125487
|
-
|
|
125488
|
-
|
|
125625
|
+
client_ledger_classPrivateFieldSet(client_transaction, this, null);
|
|
125626
|
+
await client_ledger_classPrivateFieldGet(client_ledger_storage, this).abortTransaction(transaction);
|
|
125489
125627
|
}
|
|
125490
|
-
async
|
|
125491
|
-
|
|
125492
|
-
|
|
125493
|
-
const results = await this.getVoteStaples([stapleBlockHash], from);
|
|
125494
|
-
const retval = results.get(stapleBlockHash);
|
|
125495
|
-
if (retval === undefined) {
|
|
125496
|
-
throw new Error(`internal error: missing vote staple for ${stapleBlockHash}`);
|
|
125628
|
+
async vote(blocks, otherVotes, quote) {
|
|
125629
|
+
if (blocks.length === 0) {
|
|
125630
|
+
throw new client_ledger('LEDGER_MISSING_BLOCKS', 'At least one block is required to issue a vote');
|
|
125497
125631
|
}
|
|
125498
|
-
|
|
125499
|
-
|
|
125500
|
-
async getVoteStaples(stapleBlockHashes) {
|
|
125501
|
-
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125502
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125503
|
-
if (stapleBlockHashes.length === 0) {
|
|
125504
|
-
return new client_VoteBlockHashMap();
|
|
125632
|
+
if (!client_ledger_classPrivateFieldGet(client_ledger_privateKey, this)) {
|
|
125633
|
+
throw new Error('Cannot vote on block, no private key loaded');
|
|
125505
125634
|
}
|
|
125506
|
-
if (
|
|
125507
|
-
throw new Error(
|
|
125635
|
+
if (client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode !== 'read-write') {
|
|
125636
|
+
throw new Error(`May not issue votes in read-only mode, in ${client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode} mode`);
|
|
125508
125637
|
}
|
|
125509
|
-
const
|
|
125510
|
-
|
|
125511
|
-
|
|
125512
|
-
|
|
125513
|
-
|
|
125514
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125515
|
-
const voteStapleHashes = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getHistory(transaction, account, start, limit);
|
|
125516
|
-
const voteStaplesMap = await this.getVoteStaples(voteStapleHashes, 'main');
|
|
125517
|
-
const voteStaples = voteStapleHashes.map(function (voteStapleHash) {
|
|
125518
|
-
const voteStaple = voteStaplesMap.get(voteStapleHash);
|
|
125519
|
-
if (voteStaple === undefined || voteStaple === null) {
|
|
125520
|
-
throw new Error(`internal error: missing vote staple for ${voteStapleHash}`);
|
|
125638
|
+
const privateKey = client_ledger_classPrivateFieldGet(client_ledger_privateKey, this);
|
|
125639
|
+
const ledgerPubKey = privateKey.publicKeyString.get();
|
|
125640
|
+
if (quote !== undefined) {
|
|
125641
|
+
if (otherVotes !== undefined) {
|
|
125642
|
+
throw new client_ledger('LEDGER_PERM_VOTE_WITH_QUOTE', 'Quote should not be included when requesting permanent votes');
|
|
125521
125643
|
}
|
|
125522
|
-
|
|
125523
|
-
|
|
125524
|
-
return voteStaples;
|
|
125525
|
-
}
|
|
125526
|
-
async getStaplesFromBlockHashes(hashes) {
|
|
125527
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125528
|
-
if (client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVoteStaplesFromBlockHash) {
|
|
125529
|
-
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVoteStaplesFromBlockHash(transaction, hashes, 'main');
|
|
125530
|
-
return retval;
|
|
125531
|
-
}
|
|
125532
|
-
const staples = [];
|
|
125533
|
-
const seenVoteUIDs = new Set();
|
|
125534
|
-
const seenBlockHashes = new client_block_BlockHash.Set();
|
|
125535
|
-
for (const blockHash of hashes) {
|
|
125536
|
-
if (seenBlockHashes.has(blockHash)) {
|
|
125537
|
-
continue;
|
|
125644
|
+
if (!quote.issuer.comparePublicKey(ledgerPubKey)) {
|
|
125645
|
+
throw new client_ledger('LEDGER_QUOTE_MISMATCH', 'Provided quote does not match issuer public key');
|
|
125538
125646
|
}
|
|
125647
|
+
}
|
|
125648
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125539
125649
|
|
|
125540
|
-
|
|
125541
|
-
|
|
125542
|
-
|
|
125543
|
-
|
|
125544
|
-
|
|
125545
|
-
|
|
125546
|
-
|
|
125650
|
+
/**
|
|
125651
|
+
* If there are other votes, ensure one of them was issued by
|
|
125652
|
+
* us and the blocks are in the same order as the set of
|
|
125653
|
+
* blocks we are voting on now
|
|
125654
|
+
*/
|
|
125655
|
+
if (otherVotes !== undefined) {
|
|
125656
|
+
let foundOurVote = false;
|
|
125657
|
+
const seenVoteUIDs = new Set();
|
|
125658
|
+
const seenVoteIssuers = new client_lib_account.Set();
|
|
125659
|
+
const possibleFeeBlock = blocks.at(-1);
|
|
125660
|
+
let hasFeeBlock = false;
|
|
125661
|
+
let blockCount = blocks.length;
|
|
125662
|
+
if ((possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.purpose) === client_BlockPurpose.FEE) {
|
|
125663
|
+
hasFeeBlock = true;
|
|
125664
|
+
blockCount--;
|
|
125547
125665
|
}
|
|
125548
|
-
const
|
|
125666
|
+
const requiredFees = new Map();
|
|
125667
|
+
for (const checkVote of otherVotes) {
|
|
125668
|
+
if (checkVote.quote === true) {
|
|
125669
|
+
throw new client_ledger('LEDGER_PERM_VOTE_WITH_QUOTE', 'Cannot request permanent votes with quotes');
|
|
125670
|
+
}
|
|
125671
|
+
if (seenVoteUIDs.has(checkVote.$id)) {
|
|
125672
|
+
throw new client_ledger('LEDGER_DUPLICATE_VOTE_FOUND', 'Duplicate vote UID found');
|
|
125673
|
+
}
|
|
125674
|
+
if (seenVoteIssuers.has(checkVote.issuer)) {
|
|
125675
|
+
throw new client_ledger('LEDGER_DUPLICATE_VOTE_ISSUER_FOUND', 'Multiple votes found from same issuer');
|
|
125676
|
+
}
|
|
125677
|
+
seenVoteIssuers.add(checkVote.issuer);
|
|
125678
|
+
seenVoteUIDs.add(checkVote.$id);
|
|
125679
|
+
if (checkVote.fee !== undefined) {
|
|
125680
|
+
requiredFees.set(checkVote.issuer, checkVote.fee);
|
|
125681
|
+
}
|
|
125682
|
+
if (checkVote.$permanent) {
|
|
125683
|
+
throw new client_ledger('LEDGER_CANNOT_EXCHANGE_PERM_VOTE', 'Asked to exchange a permanent vote for a permanent vote');
|
|
125684
|
+
}
|
|
125685
|
+
let blocksDifferFromVoteBlocks = checkVote.blocks.length !== blockCount;
|
|
125549
125686
|
|
|
125550
|
-
|
|
125551
|
-
|
|
125552
|
-
|
|
125553
|
-
|
|
125554
|
-
|
|
125555
|
-
|
|
125556
|
-
|
|
125557
|
-
|
|
125558
|
-
|
|
125687
|
+
/* If they do not differ from length alone, compare block hashes */
|
|
125688
|
+
if (!blocksDifferFromVoteBlocks) {
|
|
125689
|
+
for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
|
|
125690
|
+
if (!blocks[blockIndex].hash.compareHexString(checkVote.blocks[blockIndex])) {
|
|
125691
|
+
blocksDifferFromVoteBlocks = true;
|
|
125692
|
+
break;
|
|
125693
|
+
}
|
|
125694
|
+
}
|
|
125695
|
+
}
|
|
125696
|
+
if (blocksDifferFromVoteBlocks) {
|
|
125697
|
+
throw new client_ledger('LEDGER_BLOCKS_DIFFER_FROM_VOTED_ON', 'Asked to exchange different number of blocks for a permanent vote');
|
|
125698
|
+
}
|
|
125699
|
+
if (checkVote.issuer.comparePublicKey(ledgerPubKey)) {
|
|
125700
|
+
foundOurVote = true;
|
|
125701
|
+
}
|
|
125559
125702
|
}
|
|
125560
|
-
|
|
125561
|
-
|
|
125562
|
-
|
|
125563
|
-
|
|
125564
|
-
|
|
125565
|
-
|
|
125566
|
-
|
|
125567
|
-
seenVoteUIDs.add(relatedVote.$id);
|
|
125703
|
+
if (requiredFees.size > 0) {
|
|
125704
|
+
if (!hasFeeBlock) {
|
|
125705
|
+
throw new client_ledger('LEDGER_MISSING_REQUIRED_FEE_BLOCK', 'Missing fee block but votes require it');
|
|
125706
|
+
}
|
|
125707
|
+
if (requiredFees.size !== (possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.operations.length)) {
|
|
125708
|
+
throw new client_ledger('LEDGER_REQUIRED_FEE_MISMATCH', 'Fee Block Operations do not match required fees');
|
|
125709
|
+
}
|
|
125568
125710
|
}
|
|
125569
125711
|
|
|
125570
|
-
|
|
125571
|
-
|
|
125572
|
-
|
|
125573
|
-
|
|
125574
|
-
|
|
125575
|
-
|
|
125576
|
-
|
|
125577
|
-
|
|
125578
|
-
|
|
125579
|
-
|
|
125580
|
-
|
|
125581
|
-
|
|
125582
|
-
|
|
125712
|
+
// Verify that all required fees have been included in the fee block
|
|
125713
|
+
for (const [issuer, fee] of requiredFees) {
|
|
125714
|
+
const foundFee = possibleFeeBlock === null || possibleFeeBlock === void 0 ? void 0 : possibleFeeBlock.operations.find(operation => {
|
|
125715
|
+
var _fee$payTo, _fee$token;
|
|
125716
|
+
const expectedPayTo = (_fee$payTo = fee.payTo) !== null && _fee$payTo !== void 0 ? _fee$payTo : issuer;
|
|
125717
|
+
const expectedToken = (_fee$token = fee.token) !== null && _fee$token !== void 0 ? _fee$token : client_ledger_classPrivateFieldGet(src_client_ledger, this).baseToken;
|
|
125718
|
+
if (operation.type === client_OperationType.SEND && operation.to.comparePublicKey(expectedPayTo)) {
|
|
125719
|
+
if (operation.amount !== fee.amount) {
|
|
125720
|
+
throw new client_ledger('LEDGER_FEE_AMOUNT_MISMATCH', `Fee Amount Mismatch, found: ${operation.amount} expected: ${fee.amount}`);
|
|
125721
|
+
}
|
|
125722
|
+
if (!operation.token.comparePublicKey(expectedToken)) {
|
|
125723
|
+
throw new client_ledger('LEDGER_FEE_TOKEN_MISMATCH', `Fee Token Mismatch, found: ${operation.token.publicKeyString.get()} expected: ${expectedToken.publicKeyString.get()}`);
|
|
125724
|
+
}
|
|
125725
|
+
return true;
|
|
125583
125726
|
}
|
|
125584
|
-
|
|
125585
|
-
|
|
125727
|
+
return false;
|
|
125728
|
+
});
|
|
125729
|
+
if (foundFee === undefined) {
|
|
125730
|
+
var _fee$payTo$publicKeyS, _fee$payTo2;
|
|
125731
|
+
throw new client_ledger('LEDGER_FEE_MISSING', `Missing Required Fee for ${(_fee$payTo$publicKeyS = (_fee$payTo2 = fee.payTo) === null || _fee$payTo2 === void 0 ? void 0 : _fee$payTo2.publicKeyString.get()) !== null && _fee$payTo$publicKeyS !== void 0 ? _fee$payTo$publicKeyS : issuer.publicKeyString.get()}`);
|
|
125586
125732
|
}
|
|
125587
|
-
foundInvalidBlock = true;
|
|
125588
|
-
});
|
|
125589
|
-
await Promise.all(voteBlockPromises);
|
|
125590
|
-
|
|
125591
|
-
/**
|
|
125592
|
-
* If there were any blocks that we don't currently have, we shouldn't construct a staple
|
|
125593
|
-
*/
|
|
125594
|
-
if (foundInvalidBlock) {
|
|
125595
|
-
continue;
|
|
125596
125733
|
}
|
|
125597
|
-
|
|
125598
|
-
|
|
125599
|
-
|
|
125600
|
-
*/
|
|
125601
|
-
const staple = src_client_Vote.Staple.fromVotesAndBlocks(relatedVotes, resolvedVoteBlocks);
|
|
125602
|
-
staples.push(staple);
|
|
125734
|
+
if (!foundOurVote) {
|
|
125735
|
+
throw new client_ledger('LEDGER_NO_PERM_WITHOUT_SELF_TEMP', 'Asked to give a permanent vote without a temporary vote from us');
|
|
125736
|
+
}
|
|
125603
125737
|
}
|
|
125604
|
-
|
|
125605
|
-
|
|
125606
|
-
|
|
125607
|
-
|
|
125608
|
-
|
|
125609
|
-
|
|
125610
|
-
|
|
125611
|
-
|
|
125612
|
-
timeout
|
|
125613
|
-
} = options;
|
|
125614
|
-
const retval = [];
|
|
125615
|
-
const startTime = Date.now();
|
|
125616
|
-
let startKey;
|
|
125617
|
-
while (retval.length < limit) {
|
|
125618
|
-
/**
|
|
125619
|
-
* If the timeout is reached and we have at least one
|
|
125620
|
-
* result already, return it.
|
|
125621
|
-
*/
|
|
125622
|
-
if (retval.length > 0 && timeout !== undefined) {
|
|
125623
|
-
const now = Date.now();
|
|
125624
|
-
if (now - startTime > timeout) {
|
|
125625
|
-
break;
|
|
125738
|
+
const allLedgerHeads = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateBlocksForVote).call(this, blocks);
|
|
125739
|
+
const needToGetHeadFor = new client_lib_account.Set(allLedgerHeads.keys());
|
|
125740
|
+
const allHeads = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getHeadBlockHashes(transaction, needToGetHeadFor);
|
|
125741
|
+
for (const [account, expectedBlock] of allLedgerHeads.entries()) {
|
|
125742
|
+
const accountHead = allHeads[account.publicKeyString.get()];
|
|
125743
|
+
if (accountHead === null) {
|
|
125744
|
+
if (!expectedBlock.$opening) {
|
|
125745
|
+
throw new client_ledger('LEDGER_NOT_OPENING', 'Cannot vote on non-opening block for an empty account');
|
|
125626
125746
|
}
|
|
125747
|
+
continue;
|
|
125627
125748
|
}
|
|
125628
|
-
|
|
125629
|
-
|
|
125630
|
-
* Compute the maximum number of votes we can fetch from the
|
|
125631
|
-
* storage driver in a single page, we request 32x the
|
|
125632
|
-
* remaining limit, but no more than 200
|
|
125633
|
-
*/
|
|
125634
|
-
let maxVotesPerPage = (limit - retval.length) * 32;
|
|
125635
|
-
if (maxVotesPerPage > 200) {
|
|
125636
|
-
maxVotesPerPage = 200;
|
|
125749
|
+
if (expectedBlock.$opening) {
|
|
125750
|
+
throw new client_ledger('LEDGER_NOT_EMPTY', 'Cannot vote on opening block for a non-empty account');
|
|
125637
125751
|
}
|
|
125752
|
+
if (expectedBlock.previous.toString() !== accountHead.toString()) {
|
|
125753
|
+
throw new client_ledger('LEDGER_NOT_SUCCESSOR', 'The block is not the successor to the account head block');
|
|
125754
|
+
}
|
|
125755
|
+
}
|
|
125638
125756
|
|
|
125639
|
-
|
|
125640
|
-
|
|
125641
|
-
|
|
125642
|
-
|
|
125643
|
-
|
|
125644
|
-
|
|
125645
|
-
|
|
125646
|
-
|
|
125647
|
-
|
|
125648
|
-
const pageBlockHashes = page.votes.map(vote => vote.blocks);
|
|
125649
|
-
|
|
125650
|
-
// Convert BlockHash[][] to BlockHash[] and remove duplicates
|
|
125651
|
-
const seenBlockHashes = new client_block_BlockHash.Set();
|
|
125652
|
-
const flattenedHashes = pageBlockHashes.flat().filter(function (hash) {
|
|
125653
|
-
return !seenBlockHashes.has(hash);
|
|
125654
|
-
});
|
|
125655
|
-
const staples = await this.getStaplesFromBlockHashes(flattenedHashes);
|
|
125656
|
-
for (const staple of staples) {
|
|
125757
|
+
/**
|
|
125758
|
+
* Ensure we have no active vote for another conflicting successor of this block's parent (previous),
|
|
125759
|
+
* which could cause a fork
|
|
125760
|
+
*/
|
|
125761
|
+
const previousToCheckFor = blocks.map(b => b.previous);
|
|
125762
|
+
const allPrevious = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVotesFromMultiplePrevious(transaction, previousToCheckFor, 'both', client_lib_account.toAccount(ledgerPubKey));
|
|
125763
|
+
for (const block of blocks) {
|
|
125764
|
+
const previousVotes = allPrevious[block.previous.toString()];
|
|
125765
|
+
if (previousVotes !== null && previousVotes.length > 0) {
|
|
125657
125766
|
/**
|
|
125658
|
-
*
|
|
125767
|
+
* If we do have a previous vote, we can
|
|
125768
|
+
* replace it with a permanent vote if
|
|
125769
|
+
* there is only 1 previous vote, issued by us,
|
|
125770
|
+
* and it's a short vote
|
|
125659
125771
|
*/
|
|
125660
|
-
|
|
125661
|
-
|
|
125772
|
+
|
|
125773
|
+
let mayReplace = false;
|
|
125774
|
+
if (previousVotes.length === 1 && otherVotes !== undefined && otherVotes.length !== 0) {
|
|
125775
|
+
const ourVote = previousVotes[0];
|
|
125776
|
+
mayReplace = !ourVote.$permanent && ourVote.issuer.comparePublicKey(ledgerPubKey);
|
|
125777
|
+
}
|
|
125778
|
+
if (!mayReplace) {
|
|
125779
|
+
throw new client_ledger('LEDGER_SUCCESSOR_VOTE_EXISTS', `We cannot vote for this block (hash=${block.hash.toString()}), we have an existing vote for a successor (previous votes = ${JSON.stringify(client_toJSONSerializable(previousVotes))})`);
|
|
125662
125780
|
}
|
|
125781
|
+
}
|
|
125782
|
+
}
|
|
125783
|
+
|
|
125784
|
+
/**
|
|
125785
|
+
* If no other votes have been supplied, validate that the blocks are valid, and issue a short vote
|
|
125786
|
+
*/
|
|
125787
|
+
if (otherVotes === undefined) {
|
|
125788
|
+
const vote = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_voteOrQuoteWithFees).call(this, blocks, 'VOTE', quote);
|
|
125789
|
+
const blocksAndVote = src_client_VoteStaple.fromVotesAndBlocks([vote], blocks);
|
|
125790
|
+
await client_ledger_classPrivateFieldGet(client_ledger_storage, this).addPendingVote(transaction, blocksAndVote);
|
|
125791
|
+
return vote;
|
|
125792
|
+
}
|
|
125793
|
+
|
|
125794
|
+
/**
|
|
125795
|
+
* Validate the votes are sufficient weight and grant
|
|
125796
|
+
* our permanent vote
|
|
125797
|
+
*/
|
|
125798
|
+
const votesSufficient = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateVotingWeight).call(this, otherVotes);
|
|
125799
|
+
if (votesSufficient !== true) {
|
|
125800
|
+
throw new client_ledger('LEDGER_INSUFFICIENT_VOTING_WEIGHT', 'Unable to create a vote from these votes, they do not represent enough voting power');
|
|
125801
|
+
}
|
|
125802
|
+
|
|
125803
|
+
/**
|
|
125804
|
+
* Serial number
|
|
125805
|
+
*/
|
|
125806
|
+
const serial = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getNextSerialNumber(client_ledger_classPrivateFieldGet(client_transaction, this));
|
|
125807
|
+
const wipVote = new src_client_VoteBuilder(privateKey);
|
|
125808
|
+
for (const block of blocks) {
|
|
125809
|
+
wipVote.addBlock(block);
|
|
125810
|
+
}
|
|
125811
|
+
const vote = await wipVote.seal(serial, null);
|
|
125812
|
+
const blocksAndVote = src_client_VoteStaple.fromVotesAndBlocks([vote], blocks);
|
|
125663
125813
|
|
|
125664
|
-
|
|
125665
|
-
|
|
125666
|
-
|
|
125667
|
-
|
|
125668
|
-
|
|
125669
|
-
|
|
125670
|
-
|
|
125671
|
-
|
|
125672
|
-
|
|
125814
|
+
/**
|
|
125815
|
+
* Add this pending vote to our side ledger;
|
|
125816
|
+
* Replacing an existing temporary vote with a permanent one
|
|
125817
|
+
*/
|
|
125818
|
+
await client_ledger_classPrivateFieldGet(client_ledger_storage, this).addPendingVote(transaction, blocksAndVote);
|
|
125819
|
+
return vote;
|
|
125820
|
+
}
|
|
125821
|
+
async quote(blocks) {
|
|
125822
|
+
await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateBlocksForVote).call(this, blocks);
|
|
125823
|
+
const quote = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_voteOrQuoteWithFees).call(this, blocks, 'QUOTE');
|
|
125824
|
+
return quote;
|
|
125825
|
+
}
|
|
125826
|
+
async add(votesAndBlocks, from) {
|
|
125827
|
+
var _classPrivateFieldGet3, _classPrivateFieldGet4, _classPrivateFieldGet5, _classPrivateFieldGet6;
|
|
125828
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125829
|
+
switch (client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode) {
|
|
125830
|
+
case 'read-only':
|
|
125831
|
+
throw new Error('Cannot add blocks to a read-only ledger');
|
|
125832
|
+
case 'bootstrap-only':
|
|
125833
|
+
if (from === 'bootstrap') {
|
|
125834
|
+
break;
|
|
125673
125835
|
}
|
|
125674
|
-
|
|
125675
|
-
|
|
125676
|
-
|
|
125677
|
-
/**
|
|
125678
|
-
* If there is no next key, exit the loop
|
|
125679
|
-
*/
|
|
125680
|
-
if (startKey === undefined) {
|
|
125836
|
+
throw new Error('Cannot add blocks to a read-only ledger (except for bootstrapping)');
|
|
125837
|
+
case 'read-write':
|
|
125838
|
+
case 'no-voting':
|
|
125681
125839
|
break;
|
|
125840
|
+
default:
|
|
125841
|
+
throw new Error(`internal error: invalid ledger write mode: ${client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode}`);
|
|
125842
|
+
}
|
|
125843
|
+
const {
|
|
125844
|
+
votes,
|
|
125845
|
+
blocks
|
|
125846
|
+
} = votesAndBlocks;
|
|
125847
|
+
if (votes.length < 1) {
|
|
125848
|
+
throw new Error('Must have at least 1 vote in the staple');
|
|
125849
|
+
}
|
|
125850
|
+
for (const block of blocks) {
|
|
125851
|
+
if (block.network !== client_ledger_classPrivateFieldGet(client_network, this)) {
|
|
125852
|
+
throw new Error('Cannot process block for a different network');
|
|
125853
|
+
}
|
|
125854
|
+
if (block.subnet !== client_ledger_classPrivateFieldGet(client_subnet, this)) {
|
|
125855
|
+
throw new Error('Cannot process block for a different subnet');
|
|
125682
125856
|
}
|
|
125683
125857
|
}
|
|
125684
|
-
|
|
125858
|
+
for (const vote of votes) {
|
|
125859
|
+
if (!vote.$permanent) {
|
|
125860
|
+
throw new Error('Can only insert permanent votes');
|
|
125861
|
+
}
|
|
125862
|
+
}
|
|
125863
|
+
const weightTiming = (_classPrivateFieldGet3 = client_ledger_classPrivateFieldGet(src_client_ledger, this).node) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.timing.startTime('db-add/getWeight');
|
|
125864
|
+
const votesSufficient = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateVotingWeight).call(this, votesAndBlocks.votes);
|
|
125865
|
+
if (votesSufficient !== true) {
|
|
125866
|
+
throw new client_ledger('LEDGER_INSUFFICIENT_VOTING_WEIGHT', 'Votes attached do not represent enough voting power');
|
|
125867
|
+
}
|
|
125868
|
+
weightTiming === null || weightTiming === void 0 || weightTiming.end();
|
|
125869
|
+
const changesTiming = (_classPrivateFieldGet4 = client_ledger_classPrivateFieldGet(src_client_ledger, this).node) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.timing.startTime('db-add/computeEffectOfBlocks');
|
|
125870
|
+
const changes = client_computeEffectOfBlocks(votesAndBlocks.blocks, client_ledger_classPrivateFieldGet(src_client_ledger, this));
|
|
125871
|
+
changesTiming === null || changesTiming === void 0 || changesTiming.end();
|
|
125872
|
+
const adjustTiming = (_classPrivateFieldGet5 = client_ledger_classPrivateFieldGet(src_client_ledger, this).node) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.timing.startTime('db-add/adjust');
|
|
125873
|
+
const voteStaples = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).adjust(transaction, votesAndBlocks, changes);
|
|
125874
|
+
adjustTiming === null || adjustTiming === void 0 || adjustTiming.end();
|
|
125875
|
+
const postambleTiming = (_classPrivateFieldGet6 = client_ledger_classPrivateFieldGet(src_client_ledger, this).node) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.timing.startTime('db-add/postamble');
|
|
125876
|
+
/**
|
|
125877
|
+
* Add all the block hashes to the node checksum
|
|
125878
|
+
*/
|
|
125879
|
+
for (const staple of voteStaples) {
|
|
125880
|
+
for (const block of staple.blocks) {
|
|
125881
|
+
transaction.statsPending.xor('ledgerChecksum', block.hash);
|
|
125882
|
+
}
|
|
125883
|
+
}
|
|
125884
|
+
postambleTiming === null || postambleTiming === void 0 || postambleTiming.end();
|
|
125885
|
+
return voteStaples;
|
|
125685
125886
|
}
|
|
125686
|
-
async
|
|
125887
|
+
async getBalance(account, token) {
|
|
125687
125888
|
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125688
|
-
|
|
125889
|
+
const balance = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getBalance(transaction, account, token);
|
|
125890
|
+
if (balance < 0n) {
|
|
125891
|
+
throw new Error(`internal error: Account with negative balance: ${account.publicKeyString.get()}/${client_lib_account.toPublicKeyString(token)}: ${balance}`);
|
|
125892
|
+
}
|
|
125893
|
+
return balance;
|
|
125689
125894
|
}
|
|
125690
|
-
async
|
|
125691
|
-
const
|
|
125692
|
-
|
|
125895
|
+
async getAllBalances(account) {
|
|
125896
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125897
|
+
const balances = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAllBalances(transaction, account);
|
|
125898
|
+
for (const {
|
|
125899
|
+
token,
|
|
125900
|
+
balance
|
|
125901
|
+
} of balances) {
|
|
125902
|
+
if (balance < 0n) {
|
|
125903
|
+
throw new Error(`internal error: Account with negative balance: ${account.publicKeyString.get()}/${token.publicKeyString.get()}: ${balance}`);
|
|
125904
|
+
}
|
|
125905
|
+
}
|
|
125906
|
+
return balances;
|
|
125693
125907
|
}
|
|
125694
|
-
async
|
|
125908
|
+
async getAccountCertificates(account) {
|
|
125909
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125910
|
+
return await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountCertificates(client_ledger_classPrivateFieldGet(client_transaction, this), account);
|
|
125911
|
+
}
|
|
125912
|
+
async getAccountCertificateByHash(account, hash) {
|
|
125913
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125914
|
+
return await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountCertificateByHash(client_ledger_classPrivateFieldGet(client_transaction, this), account, hash);
|
|
125915
|
+
}
|
|
125916
|
+
async listACLsByPrincipal(principal, entityList) {
|
|
125695
125917
|
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125696
|
-
const
|
|
125697
|
-
return
|
|
125918
|
+
const permissions = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).listACLsByPrincipal(transaction, principal, entityList);
|
|
125919
|
+
return permissions;
|
|
125698
125920
|
}
|
|
125699
|
-
|
|
125700
|
-
|
|
125701
|
-
|
|
125702
|
-
|
|
125703
|
-
*/
|
|
125704
|
-
function client_assertTransaction() {
|
|
125705
|
-
if (client_ledger_classPrivateFieldGet(client_transaction, this) === null) {
|
|
125706
|
-
throw new Error('Attempt to use closed transaction');
|
|
125921
|
+
async listACLsByEntity(entity) {
|
|
125922
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125923
|
+
const permissions = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).listACLsByEntity(transaction, entity);
|
|
125924
|
+
return permissions;
|
|
125707
125925
|
}
|
|
125708
|
-
|
|
125709
|
-
|
|
125710
|
-
|
|
125711
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125712
|
-
const totalVotingPower = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction);
|
|
125926
|
+
async votingPower(rep) {
|
|
125927
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125928
|
+
const weight = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction, rep);
|
|
125713
125929
|
|
|
125714
|
-
|
|
125715
|
-
|
|
125716
|
-
* If so, we want to ensure that it has a vote by the trusted account, and only that account
|
|
125717
|
-
*/
|
|
125718
|
-
if (totalVotingPower === 0n) {
|
|
125719
|
-
const foundTrustedVote = votes.find(vote => {
|
|
125720
|
-
return vote.issuer.comparePublicKey(client_ledger_classPrivateFieldGet(src_client_ledger, this).initialTrustedAccount);
|
|
125721
|
-
});
|
|
125722
|
-
return foundTrustedVote !== undefined;
|
|
125930
|
+
/* Voting Power = Weight (for now) */
|
|
125931
|
+
return weight;
|
|
125723
125932
|
}
|
|
125724
|
-
|
|
125725
|
-
|
|
125726
|
-
|
|
125727
|
-
|
|
125728
|
-
|
|
125729
|
-
const votedPowerSum = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction, new client_lib_account.Set(voters));
|
|
125730
|
-
return votedPowerSum >= requiredPower;
|
|
125731
|
-
}
|
|
125732
|
-
async function client_listAccountInfo(accounts) {
|
|
125733
|
-
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125734
|
-
const accountInfo = {};
|
|
125735
|
-
const permissionPromises = Array.from(accounts).map(async account => {
|
|
125736
|
-
if (account.isIdentifier() === false) {
|
|
125737
|
-
return;
|
|
125738
|
-
}
|
|
125739
|
-
accountInfo[account.publicKeyString.get()] = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountInfo(transaction, account);
|
|
125740
|
-
});
|
|
125741
|
-
await Promise.all(permissionPromises);
|
|
125742
|
-
return accountInfo;
|
|
125743
|
-
}
|
|
125744
|
-
async function client_checkSingleAccountPermissions(account, requirements, accountInfos) {
|
|
125745
|
-
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125746
|
-
|
|
125747
|
-
// Remove duplicates in entity
|
|
125748
|
-
const unfilteredEntity = requirements.map(acct => acct.entity);
|
|
125749
|
-
const entityAccounts = new client_lib_account.Set(unfilteredEntity).toArray();
|
|
125750
|
-
const gotPermissions = await this.listACLsByPrincipal(account, entityAccounts);
|
|
125751
|
-
for (const requirement of requirements) {
|
|
125752
|
-
var _accountInfos$reqEnti;
|
|
125753
|
-
const reqEntityKey = requirement.entity.publicKeyString.get();
|
|
125754
|
-
const foundACLRow = client_findPermissionMatch(requirement, gotPermissions);
|
|
125755
|
-
let foundPermission;
|
|
125756
|
-
if (foundACLRow !== null && foundACLRow !== void 0 && foundACLRow.permissions) {
|
|
125757
|
-
foundPermission = foundACLRow === null || foundACLRow === void 0 ? void 0 : foundACLRow.permissions;
|
|
125758
|
-
} else if ((_accountInfos$reqEnti = accountInfos[reqEntityKey]) !== null && _accountInfos$reqEnti !== void 0 && _accountInfos$reqEnti.defaultPermission) {
|
|
125759
|
-
foundPermission = accountInfos[reqEntityKey].defaultPermission;
|
|
125760
|
-
} else {
|
|
125761
|
-
foundPermission = new client_permissions_Permissions();
|
|
125762
|
-
}
|
|
125763
|
-
if (requirement.permissions === null) {
|
|
125764
|
-
continue;
|
|
125765
|
-
}
|
|
125766
|
-
const hasPermissions = foundPermission.has(requirement.permissions);
|
|
125767
|
-
if (!hasPermissions) {
|
|
125768
|
-
var _requirement$target;
|
|
125769
|
-
const accountPubKey = account.publicKeyString.get();
|
|
125770
|
-
const baseFlagsStr = requirement.permissions.base.flags.join(', ');
|
|
125771
|
-
const externalOffsetsStr = requirement.permissions.external.trueOffsets.join(', ');
|
|
125772
|
-
const reqTargetKey = (_requirement$target = requirement.target) === null || _requirement$target === void 0 ? void 0 : _requirement$target.publicKeyString.get();
|
|
125773
|
-
throw new client_ledger('LEDGER_INVALID_PERMISSIONS', `${accountPubKey} does not have required permissions to perform action on ${reqEntityKey}/${reqTargetKey} -- needs [${baseFlagsStr}]/[${externalOffsetsStr}]`);
|
|
125774
|
-
}
|
|
125933
|
+
async getVotes(block) {
|
|
125934
|
+
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125935
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125936
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVotes(transaction, block, from);
|
|
125937
|
+
return retval;
|
|
125775
125938
|
}
|
|
125776
|
-
|
|
125777
|
-
|
|
125778
|
-
|
|
125779
|
-
|
|
125780
|
-
|
|
125781
|
-
|
|
125782
|
-
const allAccountsChanges = Object.values(effects);
|
|
125783
|
-
const foundMultisigSignerLengths = [];
|
|
125784
|
-
for (const {
|
|
125785
|
-
account,
|
|
125786
|
-
fields
|
|
125787
|
-
} of allAccountsChanges) {
|
|
125788
|
-
if (account.isMultisig()) {
|
|
125789
|
-
if (fields.minSignerSetLength !== undefined) {
|
|
125790
|
-
needToGetAccountInfoFor.add(account);
|
|
125791
|
-
foundMultisigSignerLengths.push([account, fields.minSignerSetLength]);
|
|
125792
|
-
}
|
|
125793
|
-
}
|
|
125794
|
-
for (const singleRequirement of (_fields$permissionReq = fields.permissionRequirements) !== null && _fields$permissionReq !== void 0 ? _fields$permissionReq : []) {
|
|
125795
|
-
var _fields$permissionReq;
|
|
125796
|
-
const principal = singleRequirement.principal;
|
|
125797
|
-
const principalPubKey = principal.publicKeyString.get();
|
|
125798
|
-
if (!requirementsByPrincipal[principalPubKey]) {
|
|
125799
|
-
requirementsByPrincipal[principalPubKey] = [];
|
|
125800
|
-
}
|
|
125801
|
-
requirementsByPrincipal[principalPubKey].push(singleRequirement);
|
|
125802
|
-
const {
|
|
125803
|
-
entity,
|
|
125804
|
-
permissions
|
|
125805
|
-
} = singleRequirement;
|
|
125806
|
-
const entityKey = entity.publicKeyString.get();
|
|
125807
|
-
if (permissions === null) {
|
|
125808
|
-
continue;
|
|
125809
|
-
}
|
|
125810
|
-
if (permissions.has(['OWNER'])) {
|
|
125811
|
-
if (newOwners[entityKey] === undefined) {
|
|
125812
|
-
newOwners[entityKey] = {
|
|
125813
|
-
entity,
|
|
125814
|
-
owners: []
|
|
125815
|
-
};
|
|
125816
|
-
}
|
|
125817
|
-
newOwners[entityKey].owners.push(principal);
|
|
125818
|
-
}
|
|
125819
|
-
if (permissions.base.isValidForDefault && entity.isIdentifier()) {
|
|
125820
|
-
needToGetAccountInfoFor.add(entity);
|
|
125821
|
-
}
|
|
125822
|
-
}
|
|
125939
|
+
async getVotesFromMultiplePrevious(prevBlocks) {
|
|
125940
|
+
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125941
|
+
let issuer = arguments.length > 2 ? arguments[2] : undefined;
|
|
125942
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125943
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVotesFromMultiplePrevious(transaction, prevBlocks, from, issuer);
|
|
125944
|
+
return retval;
|
|
125823
125945
|
}
|
|
125824
|
-
|
|
125825
|
-
|
|
125826
|
-
const
|
|
125827
|
-
|
|
125828
|
-
if (!(foundInfo !== null && foundInfo !== void 0 && foundInfo.multisigQuorum)) {
|
|
125829
|
-
throw new Error(`Multisig quorum not found for ${multisigPubKey}`);
|
|
125830
|
-
}
|
|
125831
|
-
if (foundInfo.multisigQuorum > foundSingerLength) {
|
|
125832
|
-
throw new client_ledger('LEDGER_INVALID_PERMISSIONS', `Quorum of ${foundInfo.multisigQuorum} not reached for ${multisigPubKey} -- got ${foundSingerLength}`);
|
|
125833
|
-
}
|
|
125946
|
+
async getBlockFromPrevious(block, from) {
|
|
125947
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125948
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getBlockFromPrevious(transaction, block, from);
|
|
125949
|
+
return retval;
|
|
125834
125950
|
}
|
|
125835
|
-
|
|
125836
|
-
|
|
125837
|
-
const
|
|
125838
|
-
|
|
125839
|
-
checkPromises.push(client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_checkSingleAccountPermissions).call(this, principal, accountRequirements, foundAccountInfo));
|
|
125951
|
+
async getHeadBlocks(accounts, from) {
|
|
125952
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125953
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getHeadBlocks(transaction, accounts, from);
|
|
125954
|
+
return retval;
|
|
125840
125955
|
}
|
|
125841
|
-
|
|
125842
|
-
|
|
125843
|
-
|
|
125844
|
-
|
|
125845
|
-
}
|
|
125846
|
-
|
|
125847
|
-
|
|
125848
|
-
|
|
125849
|
-
|
|
125850
|
-
|
|
125851
|
-
|
|
125852
|
-
|
|
125853
|
-
|
|
125854
|
-
|
|
125855
|
-
|
|
125856
|
-
|
|
125857
|
-
|
|
125858
|
-
|
|
125859
|
-
|
|
125860
|
-
|
|
125861
|
-
|
|
125862
|
-
|
|
125863
|
-
|
|
125864
|
-
|
|
125865
|
-
|
|
125866
|
-
|
|
125956
|
+
async getHeadBlock(account, from) {
|
|
125957
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125958
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getHeadBlock(transaction, account, from);
|
|
125959
|
+
return retval;
|
|
125960
|
+
}
|
|
125961
|
+
async getAccountRep(account) {
|
|
125962
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125963
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountRep(transaction, account);
|
|
125964
|
+
return retval;
|
|
125965
|
+
}
|
|
125966
|
+
async getAccountInfo(account) {
|
|
125967
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125968
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountInfo(transaction, account);
|
|
125969
|
+
return retval;
|
|
125970
|
+
}
|
|
125971
|
+
async getBlock(blockhash) {
|
|
125972
|
+
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125973
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125974
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getBlock(transaction, blockhash, from);
|
|
125975
|
+
return retval;
|
|
125976
|
+
}
|
|
125977
|
+
async getAccountsBlockHeightInfo(toFetch) {
|
|
125978
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125979
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountsBlockHeightInfo(transaction, toFetch);
|
|
125980
|
+
return retval;
|
|
125981
|
+
}
|
|
125982
|
+
async getVoteStaple(stapleBlockHash) {
|
|
125983
|
+
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125984
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125985
|
+
const results = await this.getVoteStaples([stapleBlockHash], from);
|
|
125986
|
+
const retval = results.get(stapleBlockHash);
|
|
125987
|
+
if (retval === undefined) {
|
|
125988
|
+
throw new Error(`internal error: missing vote staple for ${stapleBlockHash}`);
|
|
125867
125989
|
}
|
|
125868
|
-
|
|
125869
|
-
|
|
125870
|
-
|
|
125871
|
-
|
|
125872
|
-
|
|
125873
|
-
|
|
125874
|
-
|
|
125875
|
-
// Remove owner if it is already included
|
|
125876
|
-
ownersByIdentifier[entityPubKey].added.delete(principal);
|
|
125877
|
-
ownersByIdentifier[entityPubKey].removed.add(principal);
|
|
125878
|
-
break;
|
|
125990
|
+
return retval;
|
|
125991
|
+
}
|
|
125992
|
+
async getVoteStaples(stapleBlockHashes) {
|
|
125993
|
+
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
|
|
125994
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
125995
|
+
if (stapleBlockHashes.length === 0) {
|
|
125996
|
+
return new client_VoteBlockHashMap();
|
|
125879
125997
|
}
|
|
125880
|
-
|
|
125881
|
-
|
|
125882
|
-
const accountEffects = effects.accounts;
|
|
125883
|
-
const allAccountsChanges = Object.values(accountEffects);
|
|
125884
|
-
|
|
125885
|
-
/**
|
|
125886
|
-
* Ensure all required permissions are met
|
|
125887
|
-
* See which accounts are now owners, and add those accounts to the set that we have
|
|
125888
|
-
*/
|
|
125889
|
-
const {
|
|
125890
|
-
newOwners
|
|
125891
|
-
} = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_checkPermissionRequirements).call(this, accountEffects);
|
|
125892
|
-
for (const entityPubKey in newOwners) {
|
|
125893
|
-
const {
|
|
125894
|
-
entity,
|
|
125895
|
-
owners
|
|
125896
|
-
} = newOwners[entityPubKey];
|
|
125897
|
-
for (const newOwner of owners) {
|
|
125898
|
-
modifyOwners('ADD', entity, newOwner);
|
|
125998
|
+
if (stapleBlockHashes.length > 10000) {
|
|
125999
|
+
throw new Error('Cannot fetch more than 10,000 vote staples at once');
|
|
125899
126000
|
}
|
|
126001
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVoteStaples(transaction, stapleBlockHashes, from);
|
|
126002
|
+
return retval;
|
|
125900
126003
|
}
|
|
125901
|
-
|
|
125902
|
-
|
|
125903
|
-
const
|
|
125904
|
-
|
|
125905
|
-
|
|
125906
|
-
|
|
125907
|
-
|
|
125908
|
-
|
|
125909
|
-
|
|
125910
|
-
*/
|
|
125911
|
-
const createRequests = (_fields$createRequest = fields.createRequests) !== null && _fields$createRequest !== void 0 ? _fields$createRequest : [];
|
|
125912
|
-
for (const createRequest of createRequests) {
|
|
125913
|
-
modifyOwners('ADD', createRequest.createdIdentifier, account);
|
|
125914
|
-
}
|
|
125915
|
-
|
|
125916
|
-
/**
|
|
125917
|
-
* If an account was granted permissions, we should take that into effect
|
|
125918
|
-
*/
|
|
125919
|
-
const addedPermissions = (_fields$permissions = fields.permissions) !== null && _fields$permissions !== void 0 ? _fields$permissions : [];
|
|
125920
|
-
for (const newPerm of addedPermissions) {
|
|
125921
|
-
let method = 'ADD';
|
|
125922
|
-
if (newPerm.permissions === null || !newPerm.permissions.has(['OWNER'])) {
|
|
125923
|
-
method = 'REMOVE';
|
|
126004
|
+
async getHistory(account, start) {
|
|
126005
|
+
let limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 25;
|
|
126006
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126007
|
+
const voteStapleHashes = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getHistory(transaction, account, start, limit);
|
|
126008
|
+
const voteStaplesMap = await this.getVoteStaples(voteStapleHashes, 'main');
|
|
126009
|
+
const voteStaples = voteStapleHashes.map(function (voteStapleHash) {
|
|
126010
|
+
const voteStaple = voteStaplesMap.get(voteStapleHash);
|
|
126011
|
+
if (voteStaple === undefined || voteStaple === null) {
|
|
126012
|
+
throw new Error(`internal error: missing vote staple for ${voteStapleHash}`);
|
|
125924
126013
|
}
|
|
125925
|
-
|
|
125926
|
-
}
|
|
126014
|
+
return voteStaple;
|
|
126015
|
+
});
|
|
126016
|
+
return voteStaples;
|
|
125927
126017
|
}
|
|
126018
|
+
async getStaplesFromBlockHashes(hashes) {
|
|
126019
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126020
|
+
if (client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVoteStaplesFromBlockHash) {
|
|
126021
|
+
const retval = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVoteStaplesFromBlockHash(transaction, hashes, 'main');
|
|
126022
|
+
return retval;
|
|
126023
|
+
}
|
|
126024
|
+
const staples = [];
|
|
126025
|
+
const seenVoteUIDs = new Set();
|
|
126026
|
+
const seenBlockHashes = new client_block_BlockHash.Set();
|
|
126027
|
+
for (const blockHash of hashes) {
|
|
126028
|
+
if (seenBlockHashes.has(blockHash)) {
|
|
126029
|
+
continue;
|
|
126030
|
+
}
|
|
125928
126031
|
|
|
125929
|
-
|
|
125930
|
-
|
|
125931
|
-
|
|
125932
|
-
|
|
125933
|
-
|
|
125934
|
-
|
|
125935
|
-
|
|
125936
|
-
|
|
126032
|
+
/**
|
|
126033
|
+
* Get all the votes on the same set of blocks (any
|
|
126034
|
+
* block can be used for this purpose)
|
|
126035
|
+
*/
|
|
126036
|
+
const relatedVotes = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVotes(transaction, blockHash, 'main');
|
|
126037
|
+
if (!relatedVotes) {
|
|
126038
|
+
continue;
|
|
126039
|
+
}
|
|
126040
|
+
const relatedBlockHashes = relatedVotes[0].blocks;
|
|
125937
126041
|
|
|
125938
|
-
|
|
125939
|
-
|
|
125940
|
-
|
|
125941
|
-
|
|
125942
|
-
for (const
|
|
125943
|
-
|
|
125944
|
-
if (added.has(receivedOwner) || removed.has(receivedOwner)) {
|
|
125945
|
-
continue;
|
|
125946
|
-
}
|
|
125947
|
-
ownerLength++;
|
|
126042
|
+
/**
|
|
126043
|
+
* We do not need to process any blocks within this vote again
|
|
126044
|
+
* All of them will be the same staple
|
|
126045
|
+
*/
|
|
126046
|
+
for (const relatedBlockHash of relatedBlockHashes) {
|
|
126047
|
+
seenBlockHashes.add(relatedBlockHash);
|
|
125948
126048
|
}
|
|
125949
|
-
|
|
125950
|
-
|
|
125951
|
-
continue;
|
|
125952
|
-
}
|
|
125953
|
-
throw new client_ledger('LEDGER_INVALID_OWNER_COUNT', `Invalid number of owners for ${identifierPubKey} - Got ${ownerLength}/1`);
|
|
125954
|
-
}
|
|
125955
|
-
const {
|
|
125956
|
-
balances
|
|
125957
|
-
} = await client_computeLedgerEffect({
|
|
125958
|
-
checkRangeConstraints: true,
|
|
125959
|
-
baseToken: client_ledger_classPrivateFieldGet(src_client_ledger, this).baseToken
|
|
125960
|
-
}, accountEffects, client_ledger_classPrivateFieldGet(client_ledger_storage, this), client_ledger_classPrivateFieldGet(client_network, this), client_ledger_classPrivateFieldGet(client_transaction, this));
|
|
125961
|
-
for (const accountPubKey in balances) {
|
|
125962
|
-
const acctBalanceChanges = balances[accountPubKey];
|
|
125963
|
-
for (const tokenPubKey in acctBalanceChanges) {
|
|
125964
|
-
const {
|
|
125965
|
-
change,
|
|
125966
|
-
fellNegative,
|
|
125967
|
-
receiveValidated
|
|
125968
|
-
} = acctBalanceChanges[tokenPubKey];
|
|
125969
|
-
if (fellNegative) {
|
|
125970
|
-
throw new client_ledger('LEDGER_INVALID_BALANCE', `Resulting balance becomes negative at one+ point(s) during this transaction for account/token ${accountPubKey}/${tokenPubKey}: change ${change}`);
|
|
126049
|
+
if (seenVoteUIDs.has(relatedVotes[0].$id)) {
|
|
126050
|
+
continue;
|
|
125971
126051
|
}
|
|
125972
|
-
|
|
125973
|
-
|
|
126052
|
+
|
|
126053
|
+
/**
|
|
126054
|
+
* Indicate we have now seen all these votes -- even if
|
|
126055
|
+
* we cannot create a VoteStaple from it due to
|
|
126056
|
+
* missing blocks, there's no point in retrying that.
|
|
126057
|
+
*/
|
|
126058
|
+
for (const relatedVote of relatedVotes) {
|
|
126059
|
+
seenVoteUIDs.add(relatedVote.$id);
|
|
126060
|
+
}
|
|
126061
|
+
|
|
126062
|
+
/**
|
|
126063
|
+
* Fetch all the blocks mentioned in the vote
|
|
126064
|
+
*/
|
|
126065
|
+
const resolvedVoteBlocks = [];
|
|
126066
|
+
let foundInvalidBlock = false;
|
|
126067
|
+
const voteBlockPromises = relatedBlockHashes.map(async relatedHash => {
|
|
126068
|
+
try {
|
|
126069
|
+
const block = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getBlock(transaction, relatedHash, 'main');
|
|
126070
|
+
|
|
126071
|
+
// We only care about valid blocks
|
|
126072
|
+
if (src_client_Block.isInstance(block)) {
|
|
126073
|
+
resolvedVoteBlocks.push(block);
|
|
126074
|
+
return;
|
|
126075
|
+
}
|
|
126076
|
+
} catch {
|
|
126077
|
+
/* Ignore the error, we will check for undefined blocks later */
|
|
126078
|
+
}
|
|
126079
|
+
foundInvalidBlock = true;
|
|
126080
|
+
});
|
|
126081
|
+
await Promise.all(voteBlockPromises);
|
|
126082
|
+
|
|
126083
|
+
/**
|
|
126084
|
+
* If there were any blocks that we don't currently have, we shouldn't construct a staple
|
|
126085
|
+
*/
|
|
126086
|
+
if (foundInvalidBlock) {
|
|
126087
|
+
continue;
|
|
125974
126088
|
}
|
|
126089
|
+
|
|
126090
|
+
/**
|
|
126091
|
+
* Construct the staple from the information gathered
|
|
126092
|
+
*/
|
|
126093
|
+
const staple = src_client_Vote.Staple.fromVotesAndBlocks(relatedVotes, resolvedVoteBlocks);
|
|
126094
|
+
staples.push(staple);
|
|
125975
126095
|
}
|
|
126096
|
+
return staples;
|
|
125976
126097
|
}
|
|
125977
|
-
|
|
125978
|
-
|
|
125979
|
-
|
|
125980
|
-
|
|
125981
|
-
|
|
125982
|
-
|
|
125983
|
-
|
|
125984
|
-
|
|
125985
|
-
|
|
125986
|
-
|
|
125987
|
-
|
|
125988
|
-
|
|
125989
|
-
|
|
125990
|
-
|
|
125991
|
-
|
|
125992
|
-
|
|
125993
|
-
|
|
125994
|
-
|
|
125995
|
-
|
|
125996
|
-
|
|
125997
|
-
|
|
125998
|
-
|
|
125999
|
-
if (usedPreviousBlockHashes.has(prevBlockHash)) {
|
|
126000
|
-
throw new client_ledger('LEDGER_PREVIOUS_ALREADY_USED', `Invalid reference to block, previous: ${prevBlockHash} has already been used`);
|
|
126001
|
-
}
|
|
126002
|
-
usedPreviousBlockHashes.add(prevBlockHash);
|
|
126098
|
+
async getVoteStaplesAfter(moment) {
|
|
126099
|
+
let limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
126100
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
126101
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126102
|
+
const {
|
|
126103
|
+
bloomFilter,
|
|
126104
|
+
timeout
|
|
126105
|
+
} = options;
|
|
126106
|
+
const retval = [];
|
|
126107
|
+
const startTime = Date.now();
|
|
126108
|
+
let startKey;
|
|
126109
|
+
while (retval.length < limit) {
|
|
126110
|
+
/**
|
|
126111
|
+
* If the timeout is reached and we have at least one
|
|
126112
|
+
* result already, return it.
|
|
126113
|
+
*/
|
|
126114
|
+
if (retval.length > 0 && timeout !== undefined) {
|
|
126115
|
+
const now = Date.now();
|
|
126116
|
+
if (now - startTime > timeout) {
|
|
126117
|
+
break;
|
|
126118
|
+
}
|
|
126119
|
+
}
|
|
126003
126120
|
|
|
126004
|
-
|
|
126005
|
-
|
|
126006
|
-
|
|
126007
|
-
|
|
126008
|
-
|
|
126009
|
-
|
|
126010
|
-
|
|
126011
|
-
|
|
126012
|
-
|
|
126013
|
-
|
|
126014
|
-
|
|
126015
|
-
|
|
126016
|
-
|
|
126121
|
+
/**
|
|
126122
|
+
* Compute the maximum number of votes we can fetch from the
|
|
126123
|
+
* storage driver in a single page, we request 32x the
|
|
126124
|
+
* remaining limit, but no more than 200
|
|
126125
|
+
*/
|
|
126126
|
+
let maxVotesPerPage = (limit - retval.length) * 32;
|
|
126127
|
+
if (maxVotesPerPage > 200) {
|
|
126128
|
+
maxVotesPerPage = 200;
|
|
126129
|
+
}
|
|
126130
|
+
|
|
126131
|
+
/**
|
|
126132
|
+
* Get all the votes from the storage driver that occurred on
|
|
126133
|
+
* or after the moment specified.
|
|
126134
|
+
*/
|
|
126135
|
+
const page = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getVotesAfter(transaction, moment, startKey, {
|
|
126136
|
+
maxVotesPerPage,
|
|
126137
|
+
...options
|
|
126138
|
+
});
|
|
126139
|
+
startKey = page.nextKey;
|
|
126140
|
+
const pageBlockHashes = page.votes.map(vote => vote.blocks);
|
|
126141
|
+
|
|
126142
|
+
// Convert BlockHash[][] to BlockHash[] and remove duplicates
|
|
126143
|
+
const seenBlockHashes = new client_block_BlockHash.Set();
|
|
126144
|
+
const flattenedHashes = pageBlockHashes.flat().filter(function (hash) {
|
|
126145
|
+
return !seenBlockHashes.has(hash);
|
|
126146
|
+
});
|
|
126147
|
+
const staples = await this.getStaplesFromBlockHashes(flattenedHashes);
|
|
126148
|
+
for (const staple of staples) {
|
|
126149
|
+
/**
|
|
126150
|
+
* Break out of the loop if we have reached capacity
|
|
126151
|
+
*/
|
|
126152
|
+
if (retval.length >= limit) {
|
|
126153
|
+
break;
|
|
126017
126154
|
}
|
|
126018
|
-
|
|
126019
|
-
|
|
126155
|
+
|
|
126156
|
+
/**
|
|
126157
|
+
* If a filter has been supplied, check
|
|
126158
|
+
* it to see if the new vote has already
|
|
126159
|
+
* been sent
|
|
126160
|
+
*/
|
|
126161
|
+
if (bloomFilter) {
|
|
126162
|
+
if (bloomFilter.has(staple.toBytes())) {
|
|
126163
|
+
continue;
|
|
126164
|
+
}
|
|
126020
126165
|
}
|
|
126166
|
+
retval.push(staple);
|
|
126167
|
+
}
|
|
126168
|
+
|
|
126169
|
+
/**
|
|
126170
|
+
* If there is no next key, exit the loop
|
|
126171
|
+
*/
|
|
126172
|
+
if (startKey === undefined) {
|
|
126173
|
+
break;
|
|
126021
126174
|
}
|
|
126022
126175
|
}
|
|
126023
|
-
|
|
126024
|
-
allLedgerHeads.set(block.account, block);
|
|
126025
|
-
}
|
|
126176
|
+
return retval;
|
|
126026
126177
|
}
|
|
126027
|
-
|
|
126028
|
-
|
|
126029
|
-
|
|
126030
|
-
var _quote$fee;
|
|
126031
|
-
if (client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode !== 'read-write') {
|
|
126032
|
-
throw new Error(`May not issue votes in read-only mode, in ${client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode} mode`);
|
|
126178
|
+
async gc(timeLimitMS) {
|
|
126179
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126180
|
+
return await client_ledger_classPrivateFieldGet(client_ledger_storage, this).gc(transaction, timeLimitMS);
|
|
126033
126181
|
}
|
|
126034
|
-
|
|
126035
|
-
|
|
126182
|
+
async getFee(blocks, effectsInput) {
|
|
126183
|
+
const effects = effectsInput !== null && effectsInput !== void 0 ? effectsInput : client_computeEffectOfBlocks(blocks, client_ledger_classPrivateFieldGet(src_client_ledger, this));
|
|
126184
|
+
return client_ledger_classPrivateFieldGet(client_computeFeeFromBlocks, this).call(this, client_ledger_classPrivateFieldGet(src_client_ledger, this), blocks, effects);
|
|
126036
126185
|
}
|
|
126037
|
-
|
|
126038
|
-
|
|
126039
|
-
|
|
126040
|
-
|
|
126041
|
-
const blockDate = block.date.valueOf();
|
|
126042
|
-
const timeOffset = 5 /* m */ * 60 /* s */ * 1000 /* ms */;
|
|
126043
|
-
|
|
126044
|
-
/**
|
|
126045
|
-
* Do not allow short votes on blocks from the distant past
|
|
126046
|
-
*/
|
|
126047
|
-
if (blockDate < now - timeOffset || blockDate > now + timeOffset) {
|
|
126048
|
-
throw new Error(`Refusing to issue vote for block dated ${block.date.toISOString()}`);
|
|
126049
|
-
}
|
|
126186
|
+
async _testingRunStorageFunction(code) {
|
|
126187
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126188
|
+
const retval = await code(client_ledger_classPrivateFieldGet(client_ledger_storage, this), transaction);
|
|
126189
|
+
return retval;
|
|
126050
126190
|
}
|
|
126191
|
+
}
|
|
126051
126192
|
|
|
126052
|
-
|
|
126053
|
-
|
|
126054
|
-
|
|
126055
|
-
|
|
126056
|
-
|
|
126057
|
-
|
|
126058
|
-
* Short expiry (5 minutes)
|
|
126059
|
-
*/
|
|
126060
|
-
const pendingVoteExpiry = new Date();
|
|
126061
|
-
pendingVoteExpiry.setUTCMinutes(pendingVoteExpiry.getUTCMinutes() + 5);
|
|
126062
|
-
const builderType = type === 'QUOTE' ? src_client_VoteQuoteBuilder : src_client_VoteBuilder;
|
|
126063
|
-
const builder = new builderType(client_ledger_classPrivateFieldGet(client_ledger_privateKey, this));
|
|
126064
|
-
for (const block of blocks) {
|
|
126065
|
-
builder.addBlock(block);
|
|
126193
|
+
/**
|
|
126194
|
+
* The core Ledger components
|
|
126195
|
+
*/
|
|
126196
|
+
function client_assertTransaction() {
|
|
126197
|
+
if (client_ledger_classPrivateFieldGet(client_transaction, this) === null) {
|
|
126198
|
+
throw new Error('Attempt to use closed transaction');
|
|
126066
126199
|
}
|
|
126200
|
+
return client_ledger_classPrivateFieldGet(client_transaction, this);
|
|
126201
|
+
}
|
|
126202
|
+
async function client_validateVotingWeight(votes) {
|
|
126203
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126204
|
+
const totalVotingPower = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction);
|
|
126067
126205
|
|
|
126068
126206
|
/**
|
|
126069
|
-
*
|
|
126207
|
+
* See if the weight across the network is 0
|
|
126208
|
+
* If so, we want to ensure that it has a vote by the trusted account, and only that account
|
|
126070
126209
|
*/
|
|
126071
|
-
|
|
126072
|
-
|
|
126073
|
-
|
|
126210
|
+
if (totalVotingPower === 0n) {
|
|
126211
|
+
const foundTrustedVote = votes.find(vote => {
|
|
126212
|
+
return vote.issuer.comparePublicKey(client_ledger_classPrivateFieldGet(src_client_ledger, this).initialTrustedAccount);
|
|
126213
|
+
});
|
|
126214
|
+
return foundTrustedVote !== undefined;
|
|
126074
126215
|
}
|
|
126075
|
-
const
|
|
126076
|
-
|
|
126216
|
+
const twoThirdsOfTotalWeight = totalVotingPower / 3n * 2n;
|
|
126217
|
+
const requiredPower = twoThirdsOfTotalWeight + 1n;
|
|
126218
|
+
const voters = votes.map(function (vote) {
|
|
126219
|
+
return vote.issuer;
|
|
126220
|
+
});
|
|
126221
|
+
const votedPowerSum = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).delegatedWeight(transaction, new client_lib_account.Set(voters));
|
|
126222
|
+
return votedPowerSum >= requiredPower;
|
|
126077
126223
|
}
|
|
126078
|
-
|
|
126079
|
-
|
|
126080
|
-
|
|
126081
|
-
|
|
126082
|
-
|
|
126083
|
-
|
|
126084
|
-
|
|
126085
|
-
|
|
126086
|
-
|
|
126087
|
-
|
|
126088
|
-
|
|
126089
|
-
|
|
126090
|
-
|
|
126091
|
-
|
|
126092
|
-
|
|
126093
|
-
|
|
126094
|
-
|
|
126095
|
-
|
|
126096
|
-
|
|
126097
|
-
|
|
126098
|
-
|
|
126224
|
+
async function client_listAccountInfo(accounts) {
|
|
126225
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126226
|
+
const accountInfo = {};
|
|
126227
|
+
const permissionPromises = Array.from(accounts).map(async account => {
|
|
126228
|
+
if (account.isIdentifier() === false) {
|
|
126229
|
+
return;
|
|
126230
|
+
}
|
|
126231
|
+
accountInfo[account.publicKeyString.get()] = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getAccountInfo(transaction, account);
|
|
126232
|
+
});
|
|
126233
|
+
await Promise.all(permissionPromises);
|
|
126234
|
+
return accountInfo;
|
|
126235
|
+
}
|
|
126236
|
+
async function client_checkSingleAccountPermissions(account, requirements, accountInfos) {
|
|
126237
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126238
|
+
|
|
126239
|
+
// Remove duplicates in entity
|
|
126240
|
+
const unfilteredEntity = requirements.map(acct => acct.entity);
|
|
126241
|
+
const entityAccounts = new client_lib_account.Set(unfilteredEntity).toArray();
|
|
126242
|
+
const gotPermissions = await this.listACLsByPrincipal(account, entityAccounts);
|
|
126243
|
+
for (const requirement of requirements) {
|
|
126244
|
+
var _accountInfos$reqEnti;
|
|
126245
|
+
const reqEntityKey = requirement.entity.publicKeyString.get();
|
|
126246
|
+
const foundACLRow = client_findPermissionMatch(requirement, gotPermissions);
|
|
126247
|
+
let foundPermission;
|
|
126248
|
+
if (foundACLRow !== null && foundACLRow !== void 0 && foundACLRow.permissions) {
|
|
126249
|
+
foundPermission = foundACLRow === null || foundACLRow === void 0 ? void 0 : foundACLRow.permissions;
|
|
126250
|
+
} else if ((_accountInfos$reqEnti = accountInfos[reqEntityKey]) !== null && _accountInfos$reqEnti !== void 0 && _accountInfos$reqEnti.defaultPermission) {
|
|
126251
|
+
foundPermission = accountInfos[reqEntityKey].defaultPermission;
|
|
126252
|
+
} else {
|
|
126253
|
+
foundPermission = new client_permissions_Permissions();
|
|
126099
126254
|
}
|
|
126100
|
-
if (
|
|
126101
|
-
|
|
126102
|
-
return;
|
|
126255
|
+
if (requirement.permissions === null) {
|
|
126256
|
+
continue;
|
|
126103
126257
|
}
|
|
126104
|
-
|
|
126105
|
-
|
|
126106
|
-
|
|
126107
|
-
|
|
126108
|
-
|
|
126109
|
-
|
|
126110
|
-
|
|
126258
|
+
const hasPermissions = foundPermission.has(requirement.permissions);
|
|
126259
|
+
if (!hasPermissions) {
|
|
126260
|
+
var _requirement$target;
|
|
126261
|
+
const accountPubKey = account.publicKeyString.get();
|
|
126262
|
+
const baseFlagsStr = requirement.permissions.base.flags.join(', ');
|
|
126263
|
+
const externalOffsetsStr = requirement.permissions.external.trueOffsets.join(', ');
|
|
126264
|
+
const reqTargetKey = (_requirement$target = requirement.target) === null || _requirement$target === void 0 ? void 0 : _requirement$target.publicKeyString.get();
|
|
126265
|
+
throw new client_ledger('LEDGER_INVALID_PERMISSIONS', `${accountPubKey} does not have required permissions to perform action on ${reqEntityKey}/${reqTargetKey} -- needs [${baseFlagsStr}]/[${externalOffsetsStr}]`);
|
|
126111
126266
|
}
|
|
126112
|
-
return retval;
|
|
126113
|
-
}
|
|
126114
|
-
copy(newNode) {
|
|
126115
|
-
return new src_client_Ledger(client_ledger_classPrivateFieldGet(src_client_config, this), newNode, client_ledger_classPrivateFieldGet(client_storage2, this));
|
|
126116
126267
|
}
|
|
126117
|
-
|
|
126118
|
-
|
|
126119
|
-
|
|
126120
|
-
|
|
126121
|
-
|
|
126122
|
-
|
|
126123
|
-
|
|
126124
|
-
|
|
126125
|
-
|
|
126126
|
-
|
|
126127
|
-
|
|
126268
|
+
}
|
|
126269
|
+
async function client_checkPermissionRequirements(effects) {
|
|
126270
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126271
|
+
const newOwners = {};
|
|
126272
|
+
const requirementsByPrincipal = {};
|
|
126273
|
+
const needToGetAccountInfoFor = new client_lib_account.Set();
|
|
126274
|
+
const allAccountsChanges = Object.values(effects);
|
|
126275
|
+
const foundMultisigSignerLengths = [];
|
|
126276
|
+
for (const {
|
|
126277
|
+
account,
|
|
126278
|
+
fields
|
|
126279
|
+
} of allAccountsChanges) {
|
|
126280
|
+
if (account.isMultisig()) {
|
|
126281
|
+
if (fields.minSignerSetLength !== undefined) {
|
|
126282
|
+
needToGetAccountInfoFor.add(account);
|
|
126283
|
+
foundMultisigSignerLengths.push([account, fields.minSignerSetLength]);
|
|
126128
126284
|
}
|
|
126129
126285
|
}
|
|
126130
|
-
|
|
126131
|
-
|
|
126132
|
-
|
|
126133
|
-
|
|
126134
|
-
|
|
126286
|
+
for (const singleRequirement of (_fields$permissionReq = fields.permissionRequirements) !== null && _fields$permissionReq !== void 0 ? _fields$permissionReq : []) {
|
|
126287
|
+
var _fields$permissionReq;
|
|
126288
|
+
const principal = singleRequirement.principal;
|
|
126289
|
+
const principalPubKey = principal.publicKeyString.get();
|
|
126290
|
+
if (!requirementsByPrincipal[principalPubKey]) {
|
|
126291
|
+
requirementsByPrincipal[principalPubKey] = [];
|
|
126135
126292
|
}
|
|
126136
|
-
|
|
126137
|
-
|
|
126138
|
-
|
|
126139
|
-
|
|
126140
|
-
|
|
126141
|
-
|
|
126142
|
-
|
|
126143
|
-
|
|
126144
|
-
* @param code - Code to run
|
|
126145
|
-
* @returns The return value from "code"
|
|
126146
|
-
*/
|
|
126147
|
-
async run(identifier, code, readOnly) {
|
|
126148
|
-
try {
|
|
126149
|
-
var _this$node, _classPrivateFieldGet7, _classPrivateFieldGet8, _this$node4;
|
|
126150
|
-
var _usingCtx = client_usingCtx2();
|
|
126151
|
-
const _timing = _usingCtx.u((_this$node = this.node) === null || _this$node === void 0 ? void 0 : _this$node.timing.startTime(`run-${identifier}`));
|
|
126152
|
-
let retryConfig;
|
|
126153
|
-
if (((_classPrivateFieldGet7 = client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries) === null || _classPrivateFieldGet7 === void 0 ? void 0 : _classPrivateFieldGet7.maxRetries) !== undefined) {
|
|
126154
|
-
retryConfig = {
|
|
126155
|
-
mode: 'count',
|
|
126156
|
-
maxRetries: client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries.maxRetries
|
|
126157
|
-
};
|
|
126158
|
-
} else if (((_classPrivateFieldGet8 = client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries) === null || _classPrivateFieldGet8 === void 0 ? void 0 : _classPrivateFieldGet8.timeout) !== undefined) {
|
|
126159
|
-
retryConfig = {
|
|
126160
|
-
mode: 'time',
|
|
126161
|
-
timeout: client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries.timeout
|
|
126162
|
-
};
|
|
126163
|
-
} else {
|
|
126164
|
-
/* Legacy default */
|
|
126165
|
-
// retryConfig = {
|
|
126166
|
-
// mode: 'count',
|
|
126167
|
-
// maxCount: 128
|
|
126168
|
-
// };
|
|
126169
|
-
retryConfig = {
|
|
126170
|
-
mode: 'time',
|
|
126171
|
-
timeout: 5000
|
|
126172
|
-
};
|
|
126293
|
+
requirementsByPrincipal[principalPubKey].push(singleRequirement);
|
|
126294
|
+
const {
|
|
126295
|
+
entity,
|
|
126296
|
+
permissions
|
|
126297
|
+
} = singleRequirement;
|
|
126298
|
+
const entityKey = entity.publicKeyString.get();
|
|
126299
|
+
if (permissions === null) {
|
|
126300
|
+
continue;
|
|
126173
126301
|
}
|
|
126174
|
-
|
|
126175
|
-
|
|
126176
|
-
|
|
126177
|
-
|
|
126178
|
-
|
|
126179
|
-
|
|
126180
|
-
let threw = false;
|
|
126181
|
-
const transaction = await this.beginTransaction(identifier, readOnly);
|
|
126182
|
-
try {
|
|
126183
|
-
retval = await code(transaction);
|
|
126184
|
-
} catch (e) {
|
|
126185
|
-
threw = true;
|
|
126186
|
-
runError = e;
|
|
126187
|
-
}
|
|
126188
|
-
|
|
126189
|
-
// If running code was successful, commit, otherwise abort and throw error
|
|
126190
|
-
if (threw === false) {
|
|
126191
|
-
var _this$node2;
|
|
126192
|
-
await client_RequestTiming.runTimer(`${identifier}/commit`, (_this$node2 = this.node) === null || _this$node2 === void 0 ? void 0 : _this$node2.timing, async () => {
|
|
126193
|
-
await transaction.commit();
|
|
126194
|
-
});
|
|
126195
|
-
} else {
|
|
126196
|
-
var _this$node3;
|
|
126197
|
-
await client_RequestTiming.runTimer(`${identifier}/abort`, (_this$node3 = this.node) === null || _this$node3 === void 0 ? void 0 : _this$node3.timing, async () => {
|
|
126198
|
-
await transaction.abort();
|
|
126199
|
-
});
|
|
126200
|
-
throw runError;
|
|
126201
|
-
}
|
|
126202
|
-
} catch (runError) {
|
|
126203
|
-
const txnError = await client_ledger_classPrivateFieldGet(client_storage2, this).evaluateError(runError);
|
|
126204
|
-
let shouldTryToRetry = false;
|
|
126205
|
-
if (retryConfig.mode === 'count') {
|
|
126206
|
-
shouldTryToRetry = retryCount < retryConfig.maxRetries;
|
|
126207
|
-
} else if (retryConfig.mode === 'time') {
|
|
126208
|
-
const now = Date.now();
|
|
126209
|
-
shouldTryToRetry = now - startTime < retryConfig.timeout;
|
|
126210
|
-
}
|
|
126211
|
-
if (shouldTryToRetry) {
|
|
126212
|
-
if (client_ledger.isInstance(txnError)) {
|
|
126213
|
-
if (txnError.shouldRetry) {
|
|
126214
|
-
let retryDelay = 20;
|
|
126215
|
-
if (txnError.retryDelay) {
|
|
126216
|
-
retryDelay = txnError.retryDelay;
|
|
126217
|
-
}
|
|
126218
|
-
await client_asleep(retryDelay);
|
|
126219
|
-
continue;
|
|
126220
|
-
}
|
|
126221
|
-
}
|
|
126222
|
-
}
|
|
126223
|
-
throw txnError;
|
|
126302
|
+
if (permissions.has(['OWNER'])) {
|
|
126303
|
+
if (newOwners[entityKey] === undefined) {
|
|
126304
|
+
newOwners[entityKey] = {
|
|
126305
|
+
entity,
|
|
126306
|
+
owners: []
|
|
126307
|
+
};
|
|
126224
126308
|
}
|
|
126225
|
-
|
|
126309
|
+
newOwners[entityKey].owners.push(principal);
|
|
126226
126310
|
}
|
|
126227
|
-
if (
|
|
126228
|
-
|
|
126311
|
+
if (permissions.base.isValidForDefault && entity.isIdentifier()) {
|
|
126312
|
+
needToGetAccountInfoFor.add(entity);
|
|
126229
126313
|
}
|
|
126230
|
-
(_this$node4 = this.node) === null || _this$node4 === void 0 || _this$node4.stats.incr('ledger', 'dbRetries', retryCount);
|
|
126231
|
-
return retval;
|
|
126232
|
-
} catch (_) {
|
|
126233
|
-
_usingCtx.e = _;
|
|
126234
|
-
} finally {
|
|
126235
|
-
_usingCtx.d();
|
|
126236
126314
|
}
|
|
126237
126315
|
}
|
|
126238
|
-
|
|
126239
|
-
|
|
126240
|
-
|
|
126241
|
-
|
|
126242
|
-
|
|
126243
|
-
|
|
126244
|
-
node: this.node,
|
|
126245
|
-
moment: new Date(),
|
|
126246
|
-
identifier,
|
|
126247
|
-
readOnly
|
|
126248
|
-
};
|
|
126249
|
-
const transaction = await client_ledger_classPrivateFieldGet(client_storage2, this).beginTransaction(transactionBase);
|
|
126250
|
-
return new client_LedgerAtomicInterface(transaction, client_ledger_classPrivateFieldGet(client_storage2, this), client_ledger_classPrivateFieldGet(src_client_config, this), this);
|
|
126251
|
-
}
|
|
126252
|
-
async vote() {
|
|
126253
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
126254
|
-
args[_key] = arguments[_key];
|
|
126316
|
+
const foundAccountInfo = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_listAccountInfo).call(this, needToGetAccountInfoFor);
|
|
126317
|
+
for (const [multisig, foundSingerLength] of foundMultisigSignerLengths) {
|
|
126318
|
+
const multisigPubKey = multisig.publicKeyString.get();
|
|
126319
|
+
const foundInfo = foundAccountInfo[multisigPubKey];
|
|
126320
|
+
if (!(foundInfo !== null && foundInfo !== void 0 && foundInfo.multisigQuorum)) {
|
|
126321
|
+
throw new Error(`Multisig quorum not found for ${multisigPubKey}`);
|
|
126255
126322
|
}
|
|
126256
|
-
|
|
126257
|
-
|
|
126258
|
-
});
|
|
126259
|
-
}
|
|
126260
|
-
async quote() {
|
|
126261
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
126262
|
-
args[_key2] = arguments[_key2];
|
|
126323
|
+
if (foundInfo.multisigQuorum > foundSingerLength) {
|
|
126324
|
+
throw new client_ledger('LEDGER_INVALID_PERMISSIONS', `Quorum of ${foundInfo.multisigQuorum} not reached for ${multisigPubKey} -- got ${foundSingerLength}`);
|
|
126263
126325
|
}
|
|
126264
|
-
return await this.run('db-quote', async function (transaction) {
|
|
126265
|
-
return await transaction.quote(...args);
|
|
126266
|
-
});
|
|
126267
126326
|
}
|
|
126268
|
-
|
|
126269
|
-
|
|
126270
|
-
|
|
126271
|
-
|
|
126272
|
-
|
|
126273
|
-
return await transaction.add(...args);
|
|
126274
|
-
});
|
|
126327
|
+
const checkPromises = [];
|
|
126328
|
+
for (const principalPubKey in requirementsByPrincipal) {
|
|
126329
|
+
const accountRequirements = requirementsByPrincipal[principalPubKey];
|
|
126330
|
+
const principal = client_lib_account.fromPublicKeyString(principalPubKey);
|
|
126331
|
+
checkPromises.push(client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_checkSingleAccountPermissions).call(this, principal, accountRequirements, foundAccountInfo));
|
|
126275
126332
|
}
|
|
126276
|
-
|
|
126277
|
-
|
|
126278
|
-
|
|
126333
|
+
await Promise.all(checkPromises);
|
|
126334
|
+
return {
|
|
126335
|
+
newOwners
|
|
126336
|
+
};
|
|
126337
|
+
}
|
|
126338
|
+
/**
|
|
126339
|
+
* Ensure all parts of a transaction do not have a negative outcome
|
|
126340
|
+
* Balance/Supply cannot fall negative at any point in transaction
|
|
126341
|
+
* Accounts have required permissions to perform actions
|
|
126342
|
+
* After permission owner modifications all accounts must have exactly one owner
|
|
126343
|
+
*/
|
|
126344
|
+
async function client_validateLedgerOutcome(blocks) {
|
|
126345
|
+
const transaction = client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126346
|
+
const ownersByIdentifier = {};
|
|
126347
|
+
|
|
126348
|
+
// 'ADD' or 'REMOVE' an owner from ownersByIdentifier
|
|
126349
|
+
const modifyOwners = (method, entity, principal) => {
|
|
126350
|
+
if (entity.isIdentifier() === false || entity.isMultisig()) {
|
|
126351
|
+
return;
|
|
126279
126352
|
}
|
|
126280
|
-
|
|
126281
|
-
|
|
126282
|
-
|
|
126283
|
-
|
|
126284
|
-
|
|
126285
|
-
|
|
126286
|
-
args[_key5] = arguments[_key5];
|
|
126353
|
+
const entityPubKey = entity.assertIdentifier().publicKeyString.get();
|
|
126354
|
+
if (ownersByIdentifier[entityPubKey] === undefined) {
|
|
126355
|
+
ownersByIdentifier[entityPubKey] = {
|
|
126356
|
+
added: new client_lib_account.Set(),
|
|
126357
|
+
removed: new client_lib_account.Set()
|
|
126358
|
+
};
|
|
126287
126359
|
}
|
|
126288
|
-
|
|
126289
|
-
|
|
126290
|
-
|
|
126291
|
-
|
|
126292
|
-
|
|
126293
|
-
|
|
126294
|
-
|
|
126360
|
+
switch (method) {
|
|
126361
|
+
case 'ADD':
|
|
126362
|
+
// If it is not already included, push added owner
|
|
126363
|
+
ownersByIdentifier[entityPubKey].added.add(principal);
|
|
126364
|
+
ownersByIdentifier[entityPubKey].removed.delete(principal);
|
|
126365
|
+
break;
|
|
126366
|
+
case 'REMOVE':
|
|
126367
|
+
// Remove owner if it is already included
|
|
126368
|
+
ownersByIdentifier[entityPubKey].added.delete(principal);
|
|
126369
|
+
ownersByIdentifier[entityPubKey].removed.add(principal);
|
|
126370
|
+
break;
|
|
126295
126371
|
}
|
|
126296
|
-
|
|
126297
|
-
|
|
126298
|
-
|
|
126299
|
-
|
|
126300
|
-
|
|
126301
|
-
|
|
126302
|
-
|
|
126372
|
+
};
|
|
126373
|
+
const effects = client_computeEffectOfBlocks(blocks, client_ledger_classPrivateFieldGet(src_client_ledger, this));
|
|
126374
|
+
const accountEffects = effects.accounts;
|
|
126375
|
+
const allAccountsChanges = Object.values(accountEffects);
|
|
126376
|
+
|
|
126377
|
+
/**
|
|
126378
|
+
* Ensure all required permissions are met
|
|
126379
|
+
* See which accounts are now owners, and add those accounts to the set that we have
|
|
126380
|
+
*/
|
|
126381
|
+
const {
|
|
126382
|
+
newOwners
|
|
126383
|
+
} = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_checkPermissionRequirements).call(this, accountEffects);
|
|
126384
|
+
for (const entityPubKey in newOwners) {
|
|
126385
|
+
const {
|
|
126386
|
+
entity,
|
|
126387
|
+
owners
|
|
126388
|
+
} = newOwners[entityPubKey];
|
|
126389
|
+
for (const newOwner of owners) {
|
|
126390
|
+
modifyOwners('ADD', entity, newOwner);
|
|
126303
126391
|
}
|
|
126304
|
-
return await this.runReadOnly('db-getAllBalances', async function (transaction) {
|
|
126305
|
-
return await transaction.getAllBalances(...args);
|
|
126306
|
-
});
|
|
126307
126392
|
}
|
|
126308
|
-
|
|
126309
|
-
|
|
126310
|
-
|
|
126393
|
+
for (const accountChanges of allAccountsChanges) {
|
|
126394
|
+
var _fields$createRequest, _fields$permissions;
|
|
126395
|
+
const {
|
|
126396
|
+
account,
|
|
126397
|
+
fields = {}
|
|
126398
|
+
} = accountChanges;
|
|
126399
|
+
|
|
126400
|
+
/**
|
|
126401
|
+
* Newly created identifiers automatically grant the creator ownership.
|
|
126402
|
+
*/
|
|
126403
|
+
const createRequests = (_fields$createRequest = fields.createRequests) !== null && _fields$createRequest !== void 0 ? _fields$createRequest : [];
|
|
126404
|
+
for (const createRequest of createRequests) {
|
|
126405
|
+
modifyOwners('ADD', createRequest.createdIdentifier, account);
|
|
126311
126406
|
}
|
|
126312
|
-
|
|
126313
|
-
|
|
126314
|
-
|
|
126315
|
-
|
|
126316
|
-
|
|
126317
|
-
for (
|
|
126318
|
-
|
|
126407
|
+
|
|
126408
|
+
/**
|
|
126409
|
+
* If an account was granted permissions, we should take that into effect
|
|
126410
|
+
*/
|
|
126411
|
+
const addedPermissions = (_fields$permissions = fields.permissions) !== null && _fields$permissions !== void 0 ? _fields$permissions : [];
|
|
126412
|
+
for (const newPerm of addedPermissions) {
|
|
126413
|
+
let method = 'ADD';
|
|
126414
|
+
if (newPerm.permissions === null || !newPerm.permissions.has(['OWNER'])) {
|
|
126415
|
+
method = 'REMOVE';
|
|
126416
|
+
}
|
|
126417
|
+
modifyOwners(method, newPerm.entity, newPerm.principal);
|
|
126319
126418
|
}
|
|
126320
|
-
return await this.runReadOnly('db-getAccountCertificateByHash', async function (transaction) {
|
|
126321
|
-
return await transaction.getAccountCertificateByHash(...args);
|
|
126322
|
-
});
|
|
126323
126419
|
}
|
|
126324
|
-
|
|
126325
|
-
|
|
126326
|
-
|
|
126420
|
+
|
|
126421
|
+
/**
|
|
126422
|
+
* Ensure there is exactly one owner when permissions were changed
|
|
126423
|
+
*/
|
|
126424
|
+
for (const [identifierPubKey, {
|
|
126425
|
+
added,
|
|
126426
|
+
removed
|
|
126427
|
+
}] of Object.entries(ownersByIdentifier)) {
|
|
126428
|
+
let ownerLength = added.size;
|
|
126429
|
+
|
|
126430
|
+
// If more than one owner was granted and not removed, we know it is invalid without checking
|
|
126431
|
+
if (ownerLength <= 1) {
|
|
126432
|
+
const identifierAccount = client_lib_account.fromPublicKeyString(identifierPubKey).assertIdentifier();
|
|
126433
|
+
const receivedOwners = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).listOwners(transaction, identifierAccount);
|
|
126434
|
+
for (const receivedOwner of receivedOwners) {
|
|
126435
|
+
// We already know about these owners, we do not care about adding/removing them again
|
|
126436
|
+
if (added.has(receivedOwner) || removed.has(receivedOwner)) {
|
|
126437
|
+
continue;
|
|
126438
|
+
}
|
|
126439
|
+
ownerLength++;
|
|
126440
|
+
}
|
|
126327
126441
|
}
|
|
126328
|
-
|
|
126329
|
-
|
|
126330
|
-
});
|
|
126331
|
-
}
|
|
126332
|
-
async getVotes() {
|
|
126333
|
-
for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
|
126334
|
-
args[_key11] = arguments[_key11];
|
|
126442
|
+
if (ownerLength === 1) {
|
|
126443
|
+
continue;
|
|
126335
126444
|
}
|
|
126336
|
-
|
|
126337
|
-
return await transaction.getVotes(...args);
|
|
126338
|
-
});
|
|
126445
|
+
throw new client_ledger('LEDGER_INVALID_OWNER_COUNT', `Invalid number of owners for ${identifierPubKey} - Got ${ownerLength}/1`);
|
|
126339
126446
|
}
|
|
126340
|
-
|
|
126341
|
-
|
|
126342
|
-
|
|
126447
|
+
const {
|
|
126448
|
+
balances
|
|
126449
|
+
} = await client_computeLedgerEffect({
|
|
126450
|
+
checkRangeConstraints: true,
|
|
126451
|
+
baseToken: client_ledger_classPrivateFieldGet(src_client_ledger, this).baseToken
|
|
126452
|
+
}, accountEffects, client_ledger_classPrivateFieldGet(client_ledger_storage, this), client_ledger_classPrivateFieldGet(client_network, this), client_ledger_classPrivateFieldGet(client_transaction, this));
|
|
126453
|
+
for (const accountPubKey in balances) {
|
|
126454
|
+
const acctBalanceChanges = balances[accountPubKey];
|
|
126455
|
+
for (const tokenPubKey in acctBalanceChanges) {
|
|
126456
|
+
const {
|
|
126457
|
+
change,
|
|
126458
|
+
fellNegative,
|
|
126459
|
+
receiveValidated
|
|
126460
|
+
} = acctBalanceChanges[tokenPubKey];
|
|
126461
|
+
if (fellNegative) {
|
|
126462
|
+
throw new client_ledger('LEDGER_INVALID_BALANCE', `Resulting balance becomes negative at one+ point(s) during this transaction for account/token ${accountPubKey}/${tokenPubKey}: change ${change}`);
|
|
126463
|
+
}
|
|
126464
|
+
if (receiveValidated === false) {
|
|
126465
|
+
throw new client_ledger('LEDGER_RECEIVE_NOT_MET', `${accountPubKey}/${tokenPubKey} did not receive enough of requested token. change: ${change}`);
|
|
126466
|
+
}
|
|
126343
126467
|
}
|
|
126344
|
-
return await this.runReadOnly('db-getVotesFromMultiplePrevious', async function (transaction) {
|
|
126345
|
-
return await transaction.getVotesFromMultiplePrevious(...args);
|
|
126346
|
-
});
|
|
126347
126468
|
}
|
|
126348
|
-
|
|
126349
|
-
|
|
126350
|
-
|
|
126351
|
-
|
|
126352
|
-
|
|
126353
|
-
|
|
126354
|
-
|
|
126469
|
+
return effects;
|
|
126470
|
+
}
|
|
126471
|
+
async function client_validateBlocksForVote(blocks) {
|
|
126472
|
+
/**
|
|
126473
|
+
* Create a map of all blocks by their hash
|
|
126474
|
+
*/
|
|
126475
|
+
const blockHashMap = {};
|
|
126476
|
+
for (const block of blocks) {
|
|
126477
|
+
blockHashMap[block.hash.toString()] = block;
|
|
126355
126478
|
}
|
|
126356
|
-
|
|
126357
|
-
|
|
126358
|
-
|
|
126479
|
+
const seenBlockHashes = new client_block_BlockHash.Set();
|
|
126480
|
+
const usedPreviousBlockHashes = new client_block_BlockHash.Set();
|
|
126481
|
+
const allLedgerHeads = new Map();
|
|
126482
|
+
for (const block of blocks) {
|
|
126483
|
+
const prevBlockHash = block.previous;
|
|
126484
|
+
seenBlockHashes.add(block.hash);
|
|
126485
|
+
if (block.network !== client_ledger_classPrivateFieldGet(client_network, this)) {
|
|
126486
|
+
throw new client_ledger('LEDGER_INVALID_NETWORK', 'Cannot vote on block for a different network');
|
|
126359
126487
|
}
|
|
126360
|
-
|
|
126361
|
-
|
|
126362
|
-
});
|
|
126363
|
-
}
|
|
126364
|
-
async getHeadBlock() {
|
|
126365
|
-
for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
|
|
126366
|
-
args[_key15] = arguments[_key15];
|
|
126488
|
+
if (block.subnet !== client_ledger_classPrivateFieldGet(client_subnet, this)) {
|
|
126489
|
+
throw new client_ledger('LEDGER_INVALID_SUBNET', 'Cannot vote on block for a different subnet');
|
|
126367
126490
|
}
|
|
126368
|
-
|
|
126369
|
-
|
|
126370
|
-
});
|
|
126371
|
-
}
|
|
126372
|
-
async getAccountRep() {
|
|
126373
|
-
for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
|
|
126374
|
-
args[_key16] = arguments[_key16];
|
|
126491
|
+
if (usedPreviousBlockHashes.has(prevBlockHash)) {
|
|
126492
|
+
throw new client_ledger('LEDGER_PREVIOUS_ALREADY_USED', `Invalid reference to block, previous: ${prevBlockHash} has already been used`);
|
|
126375
126493
|
}
|
|
126376
|
-
|
|
126377
|
-
|
|
126378
|
-
|
|
126379
|
-
|
|
126380
|
-
|
|
126381
|
-
|
|
126382
|
-
|
|
126494
|
+
usedPreviousBlockHashes.add(prevBlockHash);
|
|
126495
|
+
|
|
126496
|
+
/**
|
|
126497
|
+
* Only allow this vote if it is the successor the current
|
|
126498
|
+
* HEAD block for the account, or if no blocks exist on the
|
|
126499
|
+
* account and its an opening block, or if the predecessor
|
|
126500
|
+
* block is also being voted on
|
|
126501
|
+
*/
|
|
126502
|
+
let predecessorBeingVotedOn = false;
|
|
126503
|
+
if (!block.$opening) {
|
|
126504
|
+
const prevBlock = blockHashMap[prevBlockHash.toString()];
|
|
126505
|
+
if (prevBlock !== undefined) {
|
|
126506
|
+
predecessorBeingVotedOn = true;
|
|
126507
|
+
if (!prevBlock.account.comparePublicKey(block.account)) {
|
|
126508
|
+
throw new client_ledger('LEDGER_INVALID_CHAIN', 'Invalid chain, changes accounts');
|
|
126509
|
+
}
|
|
126510
|
+
if (!seenBlockHashes.has(prevBlockHash)) {
|
|
126511
|
+
throw new client_ledger('LEDGER_PREVIOUS_NOT_SEEN', `Invalid reference to block, out-of-order: ${prevBlockHash} has not already been seen`);
|
|
126512
|
+
}
|
|
126513
|
+
}
|
|
126383
126514
|
}
|
|
126384
|
-
|
|
126385
|
-
|
|
126386
|
-
});
|
|
126387
|
-
}
|
|
126388
|
-
async getBlock() {
|
|
126389
|
-
for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
|
|
126390
|
-
args[_key18] = arguments[_key18];
|
|
126515
|
+
if (!predecessorBeingVotedOn) {
|
|
126516
|
+
allLedgerHeads.set(block.account, block);
|
|
126391
126517
|
}
|
|
126392
|
-
return await this.runReadOnly('db-getBlock', async function (transaction) {
|
|
126393
|
-
return await transaction.getBlock(...args);
|
|
126394
|
-
});
|
|
126395
126518
|
}
|
|
126396
|
-
|
|
126397
|
-
|
|
126398
|
-
|
|
126399
|
-
|
|
126400
|
-
|
|
126401
|
-
|
|
126402
|
-
});
|
|
126519
|
+
return allLedgerHeads;
|
|
126520
|
+
}
|
|
126521
|
+
async function client_voteOrQuoteWithFees(blocks, type, quote) {
|
|
126522
|
+
var _quote$fee;
|
|
126523
|
+
if (client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode !== 'read-write') {
|
|
126524
|
+
throw new Error(`May not issue votes in read-only mode, in ${client_ledger_classPrivateFieldGet(src_client_ledger, this).ledgerWriteMode} mode`);
|
|
126403
126525
|
}
|
|
126404
|
-
|
|
126405
|
-
|
|
126406
|
-
args[_key20] = arguments[_key20];
|
|
126407
|
-
}
|
|
126408
|
-
return await this.runReadOnly('db-getVoteStaples', async function (transaction) {
|
|
126409
|
-
return await transaction.getVoteStaples(...args);
|
|
126410
|
-
});
|
|
126526
|
+
if (!client_ledger_classPrivateFieldGet(client_ledger_privateKey, this)) {
|
|
126527
|
+
throw new Error('Cannot vote on block, no private key loaded');
|
|
126411
126528
|
}
|
|
126412
|
-
|
|
126413
|
-
|
|
126414
|
-
|
|
126529
|
+
client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_assertTransaction).call(this);
|
|
126530
|
+
const effects = await client_ledger_assertClassBrand(client_LedgerAtomicInterface_brand, this, client_validateLedgerOutcome).call(this, blocks);
|
|
126531
|
+
const now = Date.now();
|
|
126532
|
+
for (const block of blocks) {
|
|
126533
|
+
const blockDate = block.date.valueOf();
|
|
126534
|
+
const timeOffset = 5 /* m */ * 60 /* s */ * 1000 /* ms */;
|
|
126535
|
+
|
|
126536
|
+
/**
|
|
126537
|
+
* Do not allow short votes on blocks from the distant past
|
|
126538
|
+
*/
|
|
126539
|
+
if (blockDate < now - timeOffset || blockDate > now + timeOffset) {
|
|
126540
|
+
throw new Error(`Refusing to issue vote for block dated ${block.date.toISOString()}`);
|
|
126415
126541
|
}
|
|
126416
|
-
return await this.runReadOnly('db-getHistory', async function (transaction) {
|
|
126417
|
-
return await transaction.getHistory(...args);
|
|
126418
|
-
});
|
|
126419
126542
|
}
|
|
126420
|
-
|
|
126421
|
-
|
|
126422
|
-
|
|
126423
|
-
|
|
126424
|
-
|
|
126425
|
-
|
|
126426
|
-
|
|
126543
|
+
|
|
126544
|
+
/**
|
|
126545
|
+
* Serial number
|
|
126546
|
+
*/
|
|
126547
|
+
const serial = await client_ledger_classPrivateFieldGet(client_ledger_storage, this).getNextSerialNumber(client_ledger_classPrivateFieldGet(client_transaction, this));
|
|
126548
|
+
|
|
126549
|
+
/**
|
|
126550
|
+
* Short expiry (5 minutes)
|
|
126551
|
+
*/
|
|
126552
|
+
const pendingVoteExpiry = new Date();
|
|
126553
|
+
pendingVoteExpiry.setUTCMinutes(pendingVoteExpiry.getUTCMinutes() + 5);
|
|
126554
|
+
const builderType = type === 'QUOTE' ? src_client_VoteQuoteBuilder : src_client_VoteBuilder;
|
|
126555
|
+
const builder = new builderType(client_ledger_classPrivateFieldGet(client_ledger_privateKey, this));
|
|
126556
|
+
for (const block of blocks) {
|
|
126557
|
+
builder.addBlock(block);
|
|
126427
126558
|
}
|
|
126428
|
-
|
|
126429
|
-
|
|
126430
|
-
|
|
126431
|
-
|
|
126432
|
-
|
|
126433
|
-
|
|
126434
|
-
|
|
126559
|
+
|
|
126560
|
+
/**
|
|
126561
|
+
* If a quote was provided use it as the fee, otherwise generate new fee
|
|
126562
|
+
*/
|
|
126563
|
+
const fee = (_quote$fee = quote === null || quote === void 0 ? void 0 : quote.fee) !== null && _quote$fee !== void 0 ? _quote$fee : await this.getFee(blocks, effects);
|
|
126564
|
+
if (fee !== null) {
|
|
126565
|
+
builder.addFee(fee);
|
|
126435
126566
|
}
|
|
126436
|
-
|
|
126437
|
-
|
|
126438
|
-
|
|
126439
|
-
|
|
126440
|
-
|
|
126441
|
-
|
|
126567
|
+
const voteOrQuote = await builder.seal(serial, pendingVoteExpiry);
|
|
126568
|
+
return voteOrQuote;
|
|
126569
|
+
}
|
|
126570
|
+
var client_storage2 = /*#__PURE__*/new WeakMap();
|
|
126571
|
+
var src_client_config = /*#__PURE__*/new WeakMap();
|
|
126572
|
+
class src_client_Ledger {
|
|
126573
|
+
constructor(config, node, existingStorage) {
|
|
126574
|
+
client_ledger_classPrivateFieldInitSpec(this, client_storage2, void 0);
|
|
126575
|
+
client_ledger_classPrivateFieldInitSpec(this, src_client_config, void 0);
|
|
126576
|
+
client_ledger_classPrivateFieldSet(src_client_config, this, {
|
|
126577
|
+
...config
|
|
126442
126578
|
});
|
|
126443
|
-
|
|
126444
|
-
|
|
126445
|
-
|
|
126446
|
-
|
|
126579
|
+
const {
|
|
126580
|
+
baseToken,
|
|
126581
|
+
networkAddress
|
|
126582
|
+
} = client_lib_account.generateBaseAddresses(config.network);
|
|
126583
|
+
this.networkAddress = networkAddress;
|
|
126584
|
+
this.baseToken = baseToken;
|
|
126585
|
+
this.initialTrustedAccount = config.initialTrustedAccount;
|
|
126586
|
+
this.node = node;
|
|
126587
|
+
if (config.kind === client_LedgerKind.REPRESENTATIVE) {
|
|
126588
|
+
if (config.privateKey === undefined) {
|
|
126589
|
+
throw new Error('A private key must be provided if this is a Ledger for a representative');
|
|
126590
|
+
}
|
|
126447
126591
|
}
|
|
126448
|
-
|
|
126449
|
-
|
|
126450
|
-
|
|
126592
|
+
if (existingStorage !== undefined) {
|
|
126593
|
+
client_ledger_classPrivateFieldSet(client_storage2, this, existingStorage);
|
|
126594
|
+
return;
|
|
126595
|
+
}
|
|
126596
|
+
client_ledger_classPrivateFieldSet(client_storage2, this, config.storageDriver);
|
|
126597
|
+
client_ledger_classPrivateFieldGet(client_storage2, this).init(client_ledger_classPrivateFieldGet(src_client_config, this), this);
|
|
126451
126598
|
}
|
|
126452
|
-
|
|
126453
|
-
|
|
126454
|
-
|
|
126455
|
-
|
|
126456
|
-
const _timing = _usingCtx3.u((_this$node5 = this.node) === null || _this$node5 === void 0 ? void 0 : _this$node5.timing.startTime('db-stats'));
|
|
126457
|
-
const retval = await client_ledger_classPrivateFieldGet(client_storage2, this).stats();
|
|
126458
|
-
return retval;
|
|
126459
|
-
} catch (_) {
|
|
126460
|
-
_usingCtx3.e = _;
|
|
126461
|
-
} finally {
|
|
126462
|
-
_usingCtx3.d();
|
|
126599
|
+
get ledgerWriteMode() {
|
|
126600
|
+
const retval = client_ledger_classPrivateFieldGet(src_client_config, this).ledgerWriteMode;
|
|
126601
|
+
if (retval === undefined) {
|
|
126602
|
+
return 'read-write';
|
|
126463
126603
|
}
|
|
126604
|
+
return retval;
|
|
126464
126605
|
}
|
|
126465
|
-
|
|
126466
|
-
return
|
|
126467
|
-
return await transaction._testingRunStorageFunction(code);
|
|
126468
|
-
});
|
|
126606
|
+
copy(newNode) {
|
|
126607
|
+
return new src_client_Ledger(client_ledger_classPrivateFieldGet(src_client_config, this), newNode, client_ledger_classPrivateFieldGet(client_storage2, this));
|
|
126469
126608
|
}
|
|
126470
|
-
|
|
126471
|
-
|
|
126472
|
-
|
|
126473
|
-
|
|
126474
|
-
|
|
126475
|
-
|
|
126476
|
-
function client_kv_defineProperty(e, r, t) { return (r = client_kv_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
126477
|
-
function client_kv_toPropertyKey(t) { var i = client_kv_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
126478
|
-
function client_kv_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
126609
|
+
getFeePayToAndToken(accounts, token) {
|
|
126610
|
+
const retval = {};
|
|
126611
|
+
if (accounts !== undefined && accounts.length > 0) {
|
|
126612
|
+
var _classPrivateFieldGet7;
|
|
126613
|
+
// Get a random fee account from the set of possible accounts
|
|
126614
|
+
const feeAccount = accounts[Math.floor(Math.random() * accounts.length)];
|
|
126479
126615
|
|
|
126480
|
-
|
|
126481
|
-
|
|
126482
|
-
|
|
126483
|
-
|
|
126484
|
-
|
|
126485
|
-
if (key.startsWith('@buffer:')) {
|
|
126486
|
-
return;
|
|
126616
|
+
// If the fee account matches the ledger private key then we can omit the account
|
|
126617
|
+
// Fee is then paid to the vote issuer
|
|
126618
|
+
if (!feeAccount.comparePublicKey((_classPrivateFieldGet7 = client_ledger_classPrivateFieldGet(src_client_config, this).privateKey) === null || _classPrivateFieldGet7 === void 0 ? void 0 : _classPrivateFieldGet7.publicKeyString.get())) {
|
|
126619
|
+
retval.payTo = feeAccount;
|
|
126620
|
+
}
|
|
126487
126621
|
}
|
|
126488
|
-
|
|
126622
|
+
if (token !== undefined) {
|
|
126623
|
+
// If base token matches ledger fee token then we can omit the token
|
|
126624
|
+
// Fee is then paid using the base token
|
|
126625
|
+
if (!this.baseToken.comparePublicKey(token)) {
|
|
126626
|
+
retval.token = token;
|
|
126627
|
+
}
|
|
126628
|
+
}
|
|
126629
|
+
return retval;
|
|
126489
126630
|
}
|
|
126490
|
-
}
|
|
126491
|
-
;// ./src/lib/kv/kv_memory.ts
|
|
126492
|
-
function client_kv_memory_classPrivateMethodInitSpec(e, a) { client_kv_memory_checkPrivateRedeclaration(e, a), a.add(e); }
|
|
126493
|
-
function client_kv_memory_classPrivateFieldInitSpec(e, t, a) { client_kv_memory_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
126494
|
-
function client_kv_memory_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
126495
|
-
function client_kv_memory_classPrivateFieldGet(s, a) { return s.get(client_kv_memory_assertClassBrand(s, a)); }
|
|
126496
|
-
function client_kv_memory_classPrivateFieldSet(s, a, r) { return s.set(client_kv_memory_assertClassBrand(s, a), r), r; }
|
|
126497
|
-
function client_kv_memory_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
126498
126631
|
|
|
126632
|
+
/**
|
|
126633
|
+
* Execute some code with a transaction held, if the code fails the
|
|
126634
|
+
* transaction is aborted, otherwise it is committed
|
|
126635
|
+
*
|
|
126636
|
+
* @param code - Code to run
|
|
126637
|
+
* @returns The return value from "code"
|
|
126638
|
+
*/
|
|
126639
|
+
async run(identifier, code, readOnly) {
|
|
126640
|
+
try {
|
|
126641
|
+
var _this$node, _classPrivateFieldGet8, _classPrivateFieldGet9, _this$node4;
|
|
126642
|
+
var _usingCtx = client_usingCtx2();
|
|
126643
|
+
const _timing = _usingCtx.u((_this$node = this.node) === null || _this$node === void 0 ? void 0 : _this$node.timing.startTime(`run-${identifier}`));
|
|
126644
|
+
let retryConfig;
|
|
126645
|
+
if (((_classPrivateFieldGet8 = client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries) === null || _classPrivateFieldGet8 === void 0 ? void 0 : _classPrivateFieldGet8.maxRetries) !== undefined) {
|
|
126646
|
+
retryConfig = {
|
|
126647
|
+
mode: 'count',
|
|
126648
|
+
maxRetries: client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries.maxRetries
|
|
126649
|
+
};
|
|
126650
|
+
} else if (((_classPrivateFieldGet9 = client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries) === null || _classPrivateFieldGet9 === void 0 ? void 0 : _classPrivateFieldGet9.timeout) !== undefined) {
|
|
126651
|
+
retryConfig = {
|
|
126652
|
+
mode: 'time',
|
|
126653
|
+
timeout: client_ledger_classPrivateFieldGet(src_client_config, this).transactionRetries.timeout
|
|
126654
|
+
};
|
|
126655
|
+
} else {
|
|
126656
|
+
/* Legacy default */
|
|
126657
|
+
// retryConfig = {
|
|
126658
|
+
// mode: 'count',
|
|
126659
|
+
// maxCount: 128
|
|
126660
|
+
// };
|
|
126661
|
+
retryConfig = {
|
|
126662
|
+
mode: 'time',
|
|
126663
|
+
timeout: 5000
|
|
126664
|
+
};
|
|
126665
|
+
}
|
|
126666
|
+
let retval;
|
|
126667
|
+
let retryCount = 0;
|
|
126668
|
+
const startTime = Date.now();
|
|
126669
|
+
for (;; retryCount++) {
|
|
126670
|
+
try {
|
|
126671
|
+
let runError;
|
|
126672
|
+
let threw = false;
|
|
126673
|
+
const transaction = await this.beginTransaction(identifier, readOnly);
|
|
126674
|
+
try {
|
|
126675
|
+
retval = await code(transaction);
|
|
126676
|
+
} catch (e) {
|
|
126677
|
+
threw = true;
|
|
126678
|
+
runError = e;
|
|
126679
|
+
}
|
|
126499
126680
|
|
|
126500
|
-
|
|
126501
|
-
|
|
126502
|
-
|
|
126503
|
-
|
|
126504
|
-
|
|
126505
|
-
|
|
126506
|
-
}
|
|
126507
|
-
var
|
|
126508
|
-
|
|
126509
|
-
|
|
126510
|
-
|
|
126511
|
-
|
|
126512
|
-
|
|
126513
|
-
|
|
126514
|
-
|
|
126515
|
-
|
|
126516
|
-
|
|
126517
|
-
|
|
126518
|
-
|
|
126519
|
-
|
|
126520
|
-
|
|
126521
|
-
|
|
126681
|
+
// If running code was successful, commit, otherwise abort and throw error
|
|
126682
|
+
if (threw === false) {
|
|
126683
|
+
var _this$node2;
|
|
126684
|
+
await client_RequestTiming.runTimer(`${identifier}/commit`, (_this$node2 = this.node) === null || _this$node2 === void 0 ? void 0 : _this$node2.timing, async () => {
|
|
126685
|
+
await transaction.commit();
|
|
126686
|
+
});
|
|
126687
|
+
} else {
|
|
126688
|
+
var _this$node3;
|
|
126689
|
+
await client_RequestTiming.runTimer(`${identifier}/abort`, (_this$node3 = this.node) === null || _this$node3 === void 0 ? void 0 : _this$node3.timing, async () => {
|
|
126690
|
+
await transaction.abort();
|
|
126691
|
+
});
|
|
126692
|
+
throw runError;
|
|
126693
|
+
}
|
|
126694
|
+
} catch (runError) {
|
|
126695
|
+
const txnError = await client_ledger_classPrivateFieldGet(client_storage2, this).evaluateError(runError);
|
|
126696
|
+
let shouldTryToRetry = false;
|
|
126697
|
+
if (retryConfig.mode === 'count') {
|
|
126698
|
+
shouldTryToRetry = retryCount < retryConfig.maxRetries;
|
|
126699
|
+
} else if (retryConfig.mode === 'time') {
|
|
126700
|
+
const now = Date.now();
|
|
126701
|
+
shouldTryToRetry = now - startTime < retryConfig.timeout;
|
|
126702
|
+
}
|
|
126703
|
+
if (shouldTryToRetry) {
|
|
126704
|
+
if (client_ledger.isInstance(txnError)) {
|
|
126705
|
+
if (txnError.shouldRetry) {
|
|
126706
|
+
let retryDelay = 20;
|
|
126707
|
+
if (txnError.retryDelay) {
|
|
126708
|
+
retryDelay = txnError.retryDelay;
|
|
126709
|
+
}
|
|
126710
|
+
await client_asleep(retryDelay);
|
|
126711
|
+
continue;
|
|
126712
|
+
}
|
|
126713
|
+
}
|
|
126714
|
+
}
|
|
126715
|
+
throw txnError;
|
|
126522
126716
|
}
|
|
126717
|
+
break;
|
|
126523
126718
|
}
|
|
126719
|
+
if (retval === undefined) {
|
|
126720
|
+
throw new Error('Return value for run() is undefined');
|
|
126721
|
+
}
|
|
126722
|
+
(_this$node4 = this.node) === null || _this$node4 === void 0 || _this$node4.stats.incr('ledger', 'dbRetries', retryCount);
|
|
126723
|
+
return retval;
|
|
126724
|
+
} catch (_) {
|
|
126725
|
+
_usingCtx.e = _;
|
|
126726
|
+
} finally {
|
|
126727
|
+
_usingCtx.d();
|
|
126524
126728
|
}
|
|
126525
|
-
let expiry;
|
|
126526
|
-
if ((options === null || options === void 0 ? void 0 : options.ttl) !== undefined) {
|
|
126527
|
-
expiry = Date.now() + options.ttl;
|
|
126528
|
-
}
|
|
126529
|
-
if (value === undefined || value === null) {
|
|
126530
|
-
delete storeArena[key];
|
|
126531
|
-
return;
|
|
126532
|
-
}
|
|
126533
|
-
storeArena[key] = {
|
|
126534
|
-
value,
|
|
126535
|
-
expiry
|
|
126536
|
-
};
|
|
126537
126729
|
}
|
|
126538
|
-
async
|
|
126539
|
-
|
|
126540
|
-
|
|
126541
|
-
|
|
126542
|
-
|
|
126543
|
-
|
|
126544
|
-
|
|
126545
|
-
|
|
126546
|
-
|
|
126547
|
-
|
|
126548
|
-
|
|
126549
|
-
|
|
126550
|
-
|
|
126551
|
-
|
|
126552
|
-
|
|
126553
|
-
|
|
126554
|
-
}
|
|
126730
|
+
async runReadOnly(identifier, code) {
|
|
126731
|
+
return await this.run(identifier, code, true);
|
|
126732
|
+
}
|
|
126733
|
+
async beginTransaction(identifier) {
|
|
126734
|
+
let readOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
126735
|
+
const transaction = await client_ledger_classPrivateFieldGet(client_storage2, this).beginTransaction({
|
|
126736
|
+
node: this.node,
|
|
126737
|
+
moment: new Date(),
|
|
126738
|
+
identifier,
|
|
126739
|
+
readOnly
|
|
126740
|
+
});
|
|
126741
|
+
return new client_LedgerAtomicInterface(transaction, client_ledger_classPrivateFieldGet(client_storage2, this), client_ledger_classPrivateFieldGet(src_client_config, this), this);
|
|
126742
|
+
}
|
|
126743
|
+
async vote() {
|
|
126744
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
126745
|
+
args[_key] = arguments[_key];
|
|
126555
126746
|
}
|
|
126556
|
-
|
|
126557
|
-
|
|
126747
|
+
return await this.run('db-vote', async function (transaction) {
|
|
126748
|
+
return await transaction.vote(...args);
|
|
126749
|
+
});
|
|
126558
126750
|
}
|
|
126559
|
-
async
|
|
126560
|
-
|
|
126561
|
-
|
|
126562
|
-
for (const key in storeArena) {
|
|
126563
|
-
const value = await this.get(arena, key);
|
|
126564
|
-
if (value === undefined) {
|
|
126565
|
-
continue;
|
|
126566
|
-
}
|
|
126567
|
-
retval[key] = value;
|
|
126751
|
+
async quote() {
|
|
126752
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
126753
|
+
args[_key2] = arguments[_key2];
|
|
126568
126754
|
}
|
|
126569
|
-
return
|
|
126755
|
+
return await this.run('db-quote', async function (transaction) {
|
|
126756
|
+
return await transaction.quote(...args);
|
|
126757
|
+
});
|
|
126570
126758
|
}
|
|
126571
|
-
async
|
|
126572
|
-
|
|
126573
|
-
|
|
126759
|
+
async add() {
|
|
126760
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
126761
|
+
args[_key3] = arguments[_key3];
|
|
126762
|
+
}
|
|
126763
|
+
return await this.run('db-add', async function (transaction) {
|
|
126764
|
+
return await transaction.add(...args);
|
|
126765
|
+
});
|
|
126574
126766
|
}
|
|
126575
|
-
async
|
|
126576
|
-
var
|
|
126577
|
-
|
|
126578
|
-
const previous = storeArena[key];
|
|
126579
|
-
let previousValue = (_previous$value = previous === null || previous === void 0 ? void 0 : previous.value) !== null && _previous$value !== void 0 ? _previous$value : 0;
|
|
126580
|
-
if (typeof previousValue !== 'number') {
|
|
126581
|
-
throw new Error('May not increment non-number');
|
|
126767
|
+
async listACLsByPrincipal() {
|
|
126768
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
126769
|
+
args[_key4] = arguments[_key4];
|
|
126582
126770
|
}
|
|
126583
|
-
|
|
126584
|
-
|
|
126585
|
-
|
|
126586
|
-
|
|
126587
|
-
|
|
126588
|
-
|
|
126589
|
-
|
|
126771
|
+
return await this.runReadOnly('db-listACLs', async function (transaction) {
|
|
126772
|
+
return await transaction.listACLsByPrincipal(...args);
|
|
126773
|
+
});
|
|
126774
|
+
}
|
|
126775
|
+
async listACLsByEntity() {
|
|
126776
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
126777
|
+
args[_key5] = arguments[_key5];
|
|
126590
126778
|
}
|
|
126591
|
-
|
|
126592
|
-
|
|
126593
|
-
|
|
126594
|
-
expiry: newExpiry
|
|
126595
|
-
};
|
|
126596
|
-
return BigInt(newVal);
|
|
126779
|
+
return await this.runReadOnly('db-listACLs', async function (transaction) {
|
|
126780
|
+
return await transaction.listACLsByEntity(...args);
|
|
126781
|
+
});
|
|
126597
126782
|
}
|
|
126598
|
-
async
|
|
126599
|
-
|
|
126600
|
-
|
|
126601
|
-
const previous = storeArena[key];
|
|
126602
|
-
const value = previous === null || previous === void 0 ? void 0 : previous.value;
|
|
126603
|
-
if (value === undefined) {
|
|
126604
|
-
storeArena[key] = {
|
|
126605
|
-
value: change
|
|
126606
|
-
};
|
|
126607
|
-
return;
|
|
126783
|
+
async getBalance() {
|
|
126784
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
126785
|
+
args[_key6] = arguments[_key6];
|
|
126608
126786
|
}
|
|
126609
|
-
|
|
126610
|
-
|
|
126787
|
+
return await this.runReadOnly('db-getBalance', async function (transaction) {
|
|
126788
|
+
return await transaction.getBalance(...args);
|
|
126789
|
+
});
|
|
126790
|
+
}
|
|
126791
|
+
async getAllBalances() {
|
|
126792
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
126793
|
+
args[_key7] = arguments[_key7];
|
|
126611
126794
|
}
|
|
126612
|
-
|
|
126613
|
-
|
|
126614
|
-
|
|
126615
|
-
const newValue = valueBigInt ^ changeBigInt;
|
|
126616
|
-
storeArena[key] = {
|
|
126617
|
-
value: new src_client_BufferStorage(newValue, valueLength)
|
|
126618
|
-
};
|
|
126795
|
+
return await this.runReadOnly('db-getAllBalances', async function (transaction) {
|
|
126796
|
+
return await transaction.getAllBalances(...args);
|
|
126797
|
+
});
|
|
126619
126798
|
}
|
|
126620
|
-
|
|
126621
|
-
|
|
126622
|
-
|
|
126623
|
-
|
|
126799
|
+
async getAccountCertificates() {
|
|
126800
|
+
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
126801
|
+
args[_key8] = arguments[_key8];
|
|
126802
|
+
}
|
|
126803
|
+
return await this.runReadOnly('db-getAccountCertificates', async function (transaction) {
|
|
126804
|
+
return await transaction.getAccountCertificates(...args);
|
|
126805
|
+
});
|
|
126624
126806
|
}
|
|
126625
|
-
|
|
126626
|
-
|
|
126627
|
-
|
|
126628
|
-
;// ./src/lib/stats.ts
|
|
126629
|
-
function client_stats_classPrivateMethodInitSpec(e, a) { client_stats_checkPrivateRedeclaration(e, a), a.add(e); }
|
|
126630
|
-
function client_stats_classPrivateFieldInitSpec(e, t, a) { client_stats_checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
126631
|
-
function client_stats_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
126632
|
-
function client_stats_classPrivateFieldGet(s, a) { return s.get(client_stats_assertClassBrand(s, a)); }
|
|
126633
|
-
function client_stats_classPrivateFieldSet(s, a, r) { return s.set(client_stats_assertClassBrand(s, a), r), r; }
|
|
126634
|
-
function client_stats_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
126635
|
-
|
|
126636
|
-
|
|
126637
|
-
|
|
126638
|
-
/**
|
|
126639
|
-
* Size of the XOR buffer objects -- we use them for block hashes so they
|
|
126640
|
-
* should be the same size as a block hash
|
|
126641
|
-
*/
|
|
126642
|
-
const client_XOR_BUFFER_SIZE = client_HashFunctionLength;
|
|
126643
|
-
const client_durationRanges = {
|
|
126644
|
-
'-1ms': [-1, -1],
|
|
126645
|
-
'0ms': [0, 0],
|
|
126646
|
-
'10ms': [1, 10],
|
|
126647
|
-
'100ms': [11, 100],
|
|
126648
|
-
'200ms': [101, 200],
|
|
126649
|
-
'300ms': [201, 300],
|
|
126650
|
-
'400ms': [301, 400],
|
|
126651
|
-
'500ms': [401, 500],
|
|
126652
|
-
'600ms': [501, 600],
|
|
126653
|
-
'700ms': [601, 700],
|
|
126654
|
-
'800ms': [701, 800],
|
|
126655
|
-
'900ms': [801, 900],
|
|
126656
|
-
'1000ms': [901, 1000],
|
|
126657
|
-
'1500ms': [1001, 1500],
|
|
126658
|
-
'2000ms': [1501, 2000],
|
|
126659
|
-
'5000ms': [2001, 5000],
|
|
126660
|
-
'10000ms': [5001, 10000],
|
|
126661
|
-
'100000ms': [10001, 100000],
|
|
126662
|
-
'ExtraLong': [100000, Number.MAX_SAFE_INTEGER]
|
|
126663
|
-
};
|
|
126664
|
-
var client_localDBIncr = /*#__PURE__*/new WeakMap();
|
|
126665
|
-
var client_localDBXOR = /*#__PURE__*/new WeakMap();
|
|
126666
|
-
var client_syncPromise = /*#__PURE__*/new WeakMap();
|
|
126667
|
-
var client_kv = /*#__PURE__*/new WeakMap();
|
|
126668
|
-
var client_Stats_brand = /*#__PURE__*/new WeakSet();
|
|
126669
|
-
class client_Stats {
|
|
126670
|
-
constructor(config) {
|
|
126671
|
-
client_stats_classPrivateMethodInitSpec(this, client_Stats_brand);
|
|
126672
|
-
client_stats_classPrivateFieldInitSpec(this, client_localDBIncr, {});
|
|
126673
|
-
client_stats_classPrivateFieldInitSpec(this, client_localDBXOR, {});
|
|
126674
|
-
client_stats_classPrivateFieldInitSpec(this, client_syncPromise, void 0);
|
|
126675
|
-
client_stats_classPrivateFieldInitSpec(this, client_kv, void 0);
|
|
126676
|
-
let kv = config.kv;
|
|
126677
|
-
if (kv === null) {
|
|
126678
|
-
kv = new client_kv_memory();
|
|
126807
|
+
async getAccountCertificateByHash() {
|
|
126808
|
+
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
126809
|
+
args[_key9] = arguments[_key9];
|
|
126679
126810
|
}
|
|
126680
|
-
|
|
126811
|
+
return await this.runReadOnly('db-getAccountCertificateByHash', async function (transaction) {
|
|
126812
|
+
return await transaction.getAccountCertificateByHash(...args);
|
|
126813
|
+
});
|
|
126681
126814
|
}
|
|
126682
|
-
|
|
126683
|
-
|
|
126684
|
-
|
|
126685
|
-
|
|
126686
|
-
return
|
|
126815
|
+
async votingPower() {
|
|
126816
|
+
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
|
126817
|
+
args[_key10] = arguments[_key10];
|
|
126818
|
+
}
|
|
126819
|
+
return await this.runReadOnly('db-votingPower', async function (transaction) {
|
|
126820
|
+
return await transaction.votingPower(...args);
|
|
126821
|
+
});
|
|
126687
126822
|
}
|
|
126688
|
-
|
|
126689
|
-
|
|
126690
|
-
|
|
126823
|
+
async getVotes() {
|
|
126824
|
+
for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
|
126825
|
+
args[_key11] = arguments[_key11];
|
|
126691
126826
|
}
|
|
126827
|
+
return await this.runReadOnly('db-getVotes', async function (transaction) {
|
|
126828
|
+
return await transaction.getVotes(...args);
|
|
126829
|
+
});
|
|
126692
126830
|
}
|
|
126693
|
-
|
|
126694
|
-
|
|
126695
|
-
|
|
126696
|
-
|
|
126697
|
-
if (duration < 0) {
|
|
126698
|
-
duration = 0;
|
|
126831
|
+
async getVotesFromMultiplePrevious() {
|
|
126832
|
+
for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
|
|
126833
|
+
args[_key12] = arguments[_key12];
|
|
126699
126834
|
}
|
|
126700
|
-
|
|
126701
|
-
|
|
126702
|
-
|
|
126703
|
-
|
|
126704
|
-
|
|
126835
|
+
return await this.runReadOnly('db-getVotesFromMultiplePrevious', async function (transaction) {
|
|
126836
|
+
return await transaction.getVotesFromMultiplePrevious(...args);
|
|
126837
|
+
});
|
|
126838
|
+
}
|
|
126839
|
+
async getBlockFromPrevious() {
|
|
126840
|
+
for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
|
|
126841
|
+
args[_key13] = arguments[_key13];
|
|
126705
126842
|
}
|
|
126706
|
-
|
|
126843
|
+
return await this.runReadOnly('db-getBlockFromPrevious', async function (transaction) {
|
|
126844
|
+
return await transaction.getBlockFromPrevious(...args);
|
|
126845
|
+
});
|
|
126707
126846
|
}
|
|
126708
|
-
|
|
126709
|
-
|
|
126710
|
-
|
|
126711
|
-
ret[key] = {
|
|
126712
|
-
count: -1,
|
|
126713
|
-
range: client_stats_assertClassBrand(client_Stats, this, client_getDurationRange).call(this, key)
|
|
126714
|
-
};
|
|
126847
|
+
async getHeadBlocks() {
|
|
126848
|
+
for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
|
|
126849
|
+
args[_key14] = arguments[_key14];
|
|
126715
126850
|
}
|
|
126716
|
-
|
|
126717
|
-
|
|
126718
|
-
|
|
126719
|
-
return ret;
|
|
126851
|
+
return await this.runReadOnly('db-getHeadBlocks', async function (transaction) {
|
|
126852
|
+
return await transaction.getHeadBlocks(...args);
|
|
126853
|
+
});
|
|
126720
126854
|
}
|
|
126721
|
-
|
|
126722
|
-
|
|
126723
|
-
|
|
126724
|
-
if (client_stats_classPrivateFieldGet(client_localDBIncr, this)[compoundKey] === undefined) {
|
|
126725
|
-
client_stats_classPrivateFieldGet(client_localDBIncr, this)[compoundKey] = 0;
|
|
126855
|
+
async getHeadBlock() {
|
|
126856
|
+
for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
|
|
126857
|
+
args[_key15] = arguments[_key15];
|
|
126726
126858
|
}
|
|
126727
|
-
|
|
126859
|
+
return await this.runReadOnly('db-getHeadBlock', async function (transaction) {
|
|
126860
|
+
return await transaction.getHeadBlock(...args);
|
|
126861
|
+
});
|
|
126728
126862
|
}
|
|
126729
|
-
|
|
126730
|
-
|
|
126731
|
-
|
|
126732
|
-
if (existingValue === undefined) {
|
|
126733
|
-
client_stats_classPrivateFieldGet(client_localDBXOR, this)[key] = changeValue;
|
|
126734
|
-
return;
|
|
126863
|
+
async getAccountRep() {
|
|
126864
|
+
for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
|
|
126865
|
+
args[_key16] = arguments[_key16];
|
|
126735
126866
|
}
|
|
126736
|
-
|
|
126867
|
+
return await this.runReadOnly('db-getAccountRep', async function (transaction) {
|
|
126868
|
+
return await transaction.getAccountRep(...args);
|
|
126869
|
+
});
|
|
126737
126870
|
}
|
|
126738
|
-
async
|
|
126739
|
-
|
|
126740
|
-
|
|
126741
|
-
const baseString = await client_stats_classPrivateFieldGet(client_kv, this).get(null, bufferKey);
|
|
126742
|
-
let base = 0n;
|
|
126743
|
-
if (baseString !== undefined) {
|
|
126744
|
-
base = BigInt(`0x${baseString}`);
|
|
126871
|
+
async getAccountInfo() {
|
|
126872
|
+
for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
|
|
126873
|
+
args[_key17] = arguments[_key17];
|
|
126745
126874
|
}
|
|
126746
|
-
|
|
126747
|
-
|
|
126748
|
-
|
|
126875
|
+
return await this.runReadOnly('db-getAccountInfo', async function (transaction) {
|
|
126876
|
+
return await transaction.getAccountInfo(...args);
|
|
126877
|
+
});
|
|
126878
|
+
}
|
|
126879
|
+
async getBlock() {
|
|
126880
|
+
for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
|
|
126881
|
+
args[_key18] = arguments[_key18];
|
|
126749
126882
|
}
|
|
126750
|
-
|
|
126751
|
-
|
|
126752
|
-
|
|
126883
|
+
return await this.runReadOnly('db-getBlock', async function (transaction) {
|
|
126884
|
+
return await transaction.getBlock(...args);
|
|
126885
|
+
});
|
|
126753
126886
|
}
|
|
126754
|
-
|
|
126755
|
-
|
|
126756
|
-
|
|
126757
|
-
let returnOnly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
126758
|
-
const breakdown = client_Stats.durationBreakdown(duration);
|
|
126759
|
-
const params = [arena, `${category}@${breakdown}`, 1];
|
|
126760
|
-
if (returnOnly !== true) {
|
|
126761
|
-
this.incr(...params);
|
|
126887
|
+
async getAccountsBlockHeightInfo() {
|
|
126888
|
+
for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
|
|
126889
|
+
args[_key19] = arguments[_key19];
|
|
126762
126890
|
}
|
|
126763
|
-
return
|
|
126891
|
+
return await this.runReadOnly('db-getAccountsBlockHeightInfo', async function (transaction) {
|
|
126892
|
+
return await transaction.getAccountsBlockHeightInfo(...args);
|
|
126893
|
+
});
|
|
126764
126894
|
}
|
|
126765
|
-
|
|
126766
|
-
|
|
126767
|
-
|
|
126768
|
-
for (const sectionInfo of Object.values(timing.getAllTiming())) {
|
|
126769
|
-
const duration = sectionInfo.duration;
|
|
126770
|
-
const name = sectionInfo.name;
|
|
126771
|
-
retval.push(this.addTimingPoint(arena, name, duration, returnOnly));
|
|
126895
|
+
async getVoteStaple() {
|
|
126896
|
+
for (var _len20 = arguments.length, args = new Array(_len20), _key20 = 0; _key20 < _len20; _key20++) {
|
|
126897
|
+
args[_key20] = arguments[_key20];
|
|
126772
126898
|
}
|
|
126773
|
-
return
|
|
126899
|
+
return await this.runReadOnly('db-getVoteStaple', async function (transaction) {
|
|
126900
|
+
return await transaction.getVoteStaple(...args);
|
|
126901
|
+
});
|
|
126774
126902
|
}
|
|
126775
|
-
async
|
|
126776
|
-
|
|
126777
|
-
|
|
126778
|
-
let base = await client_stats_classPrivateFieldGet(client_kv, this).get('stats', compoundKey);
|
|
126779
|
-
if (base === undefined) {
|
|
126780
|
-
base = 0;
|
|
126903
|
+
async getVoteStaples() {
|
|
126904
|
+
for (var _len21 = arguments.length, args = new Array(_len21), _key21 = 0; _key21 < _len21; _key21++) {
|
|
126905
|
+
args[_key21] = arguments[_key21];
|
|
126781
126906
|
}
|
|
126782
|
-
|
|
126783
|
-
|
|
126907
|
+
return await this.runReadOnly('db-getVoteStaples', async function (transaction) {
|
|
126908
|
+
return await transaction.getVoteStaples(...args);
|
|
126909
|
+
});
|
|
126910
|
+
}
|
|
126911
|
+
async getHistory() {
|
|
126912
|
+
for (var _len22 = arguments.length, args = new Array(_len22), _key22 = 0; _key22 < _len22; _key22++) {
|
|
126913
|
+
args[_key22] = arguments[_key22];
|
|
126784
126914
|
}
|
|
126785
|
-
|
|
126786
|
-
|
|
126915
|
+
return await this.runReadOnly('db-getHistory', async function (transaction) {
|
|
126916
|
+
return await transaction.getHistory(...args);
|
|
126917
|
+
});
|
|
126918
|
+
}
|
|
126919
|
+
async getStaplesFromBlockHashes() {
|
|
126920
|
+
for (var _len23 = arguments.length, args = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) {
|
|
126921
|
+
args[_key23] = arguments[_key23];
|
|
126787
126922
|
}
|
|
126788
|
-
|
|
126789
|
-
|
|
126790
|
-
|
|
126923
|
+
return await this.runReadOnly('db-getStaplesFromBlockHashes', async function (transaction) {
|
|
126924
|
+
return await transaction.getStaplesFromBlockHashes(...args);
|
|
126925
|
+
});
|
|
126926
|
+
}
|
|
126927
|
+
async getVoteStaplesAfter() {
|
|
126928
|
+
for (var _len24 = arguments.length, args = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) {
|
|
126929
|
+
args[_key24] = arguments[_key24];
|
|
126791
126930
|
}
|
|
126792
|
-
return
|
|
126931
|
+
return await this.runReadOnly('db-getVoteStaplesAfter', async function (transaction) {
|
|
126932
|
+
return await transaction.getVoteStaplesAfter(...args);
|
|
126933
|
+
});
|
|
126793
126934
|
}
|
|
126794
|
-
|
|
126795
|
-
|
|
126796
|
-
|
|
126797
|
-
|
|
126798
|
-
|
|
126799
|
-
|
|
126800
|
-
|
|
126801
|
-
const key = `${category}@${breakdown}`;
|
|
126802
|
-
const range = client_getDurationRange.call(client_Stats, breakdown);
|
|
126803
|
-
let count = -1;
|
|
126804
|
-
try {
|
|
126805
|
-
count = await this.get(arena, key);
|
|
126806
|
-
} catch (_ignored_error) {
|
|
126807
|
-
/* Errors fetching single stat are ignored */
|
|
126808
|
-
} finally {
|
|
126809
|
-
retval[breakdown] = {
|
|
126810
|
-
count,
|
|
126811
|
-
range
|
|
126812
|
-
};
|
|
126813
|
-
}
|
|
126814
|
-
}));
|
|
126815
|
-
return retval;
|
|
126935
|
+
async gc() {
|
|
126936
|
+
for (var _len25 = arguments.length, args = new Array(_len25), _key25 = 0; _key25 < _len25; _key25++) {
|
|
126937
|
+
args[_key25] = arguments[_key25];
|
|
126938
|
+
}
|
|
126939
|
+
return await this.run('db-gc', async function (transaction) {
|
|
126940
|
+
return await transaction.gc(...args);
|
|
126941
|
+
});
|
|
126816
126942
|
}
|
|
126817
|
-
async
|
|
126818
|
-
|
|
126819
|
-
|
|
126820
|
-
|
|
126821
|
-
|
|
126822
|
-
|
|
126823
|
-
|
|
126824
|
-
const updatePromises = [];
|
|
126825
|
-
for (const [key, value] of localDBIncr) {
|
|
126826
|
-
if (value === undefined) {
|
|
126827
|
-
continue;
|
|
126828
|
-
}
|
|
126829
|
-
updatePromises.push(client_stats_classPrivateFieldGet(client_kv, this).incr('stats', key, value));
|
|
126830
|
-
}
|
|
126831
|
-
for (const [key, value] of localDBXOR) {
|
|
126832
|
-
if (value === undefined) {
|
|
126833
|
-
continue;
|
|
126834
|
-
}
|
|
126835
|
-
const valueBuffer = new src_client_BufferStorage(value, client_XOR_BUFFER_SIZE);
|
|
126836
|
-
const bufferKey = `@buffer:${key}`;
|
|
126837
|
-
updatePromises.push(client_stats_classPrivateFieldGet(client_kv, this).xor(null, bufferKey, valueBuffer));
|
|
126838
|
-
}
|
|
126839
|
-
await Promise.all(updatePromises);
|
|
126840
|
-
})());
|
|
126841
|
-
await client_stats_classPrivateFieldGet(client_syncPromise, this);
|
|
126842
|
-
client_stats_classPrivateFieldSet(client_syncPromise, this, undefined);
|
|
126943
|
+
async getFee() {
|
|
126944
|
+
for (var _len26 = arguments.length, args = new Array(_len26), _key26 = 0; _key26 < _len26; _key26++) {
|
|
126945
|
+
args[_key26] = arguments[_key26];
|
|
126946
|
+
}
|
|
126947
|
+
return await this.runReadOnly('db-getFee', async function (transaction) {
|
|
126948
|
+
return await transaction.getFee(...args);
|
|
126949
|
+
});
|
|
126843
126950
|
}
|
|
126844
|
-
|
|
126845
|
-
|
|
126846
|
-
|
|
126847
|
-
|
|
126848
|
-
|
|
126849
|
-
|
|
126850
|
-
|
|
126851
|
-
|
|
126951
|
+
async stats() {
|
|
126952
|
+
try {
|
|
126953
|
+
var _this$node5;
|
|
126954
|
+
var _usingCtx3 = client_usingCtx2();
|
|
126955
|
+
const _timing = _usingCtx3.u((_this$node5 = this.node) === null || _this$node5 === void 0 ? void 0 : _this$node5.timing.startTime('db-stats'));
|
|
126956
|
+
const retval = await client_ledger_classPrivateFieldGet(client_storage2, this).stats();
|
|
126957
|
+
return retval;
|
|
126958
|
+
} catch (_) {
|
|
126959
|
+
_usingCtx3.e = _;
|
|
126960
|
+
} finally {
|
|
126961
|
+
_usingCtx3.d();
|
|
126962
|
+
}
|
|
126852
126963
|
}
|
|
126853
|
-
|
|
126854
|
-
function
|
|
126855
|
-
|
|
126856
|
-
|
|
126857
|
-
if (!range) {
|
|
126858
|
-
throw new Error(`Could not get range for invalid duration: ${duration}, got range ${range}`);
|
|
126964
|
+
async _testingRunStorageFunction(code) {
|
|
126965
|
+
return await this.run('db-runStorageFunction', async function (transaction) {
|
|
126966
|
+
return await transaction._testingRunStorageFunction(code);
|
|
126967
|
+
});
|
|
126859
126968
|
}
|
|
126860
|
-
|
|
126861
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
126862
|
-
return range;
|
|
126863
126969
|
}
|
|
126864
|
-
|
|
126970
|
+
client_Ledger = src_client_Ledger;
|
|
126971
|
+
client_lib_ledger_defineProperty(src_client_Ledger, "Kind", client_LedgerKind);
|
|
126972
|
+
client_lib_ledger_defineProperty(src_client_Ledger, "isInstance", client_checkableGenerator(client_Ledger));
|
|
126973
|
+
/* harmony default export */ const client_lib_ledger = (src_client_Ledger);
|
|
126865
126974
|
// EXTERNAL MODULE: ws (ignored)
|
|
126866
126975
|
var client_ws_ignored_ = __webpack_require__(4708);
|
|
126867
126976
|
;// ./src/version.ts
|
|
126868
|
-
const client_version = '0.14.
|
|
126977
|
+
const client_version = '0.14.3+gc0f4c96265aa999e6f32e3b21443d294bbf33806';
|
|
126869
126978
|
/* harmony default export */ const client_src_version = ((/* unused pure expression or super */ null && (client_version)));
|
|
126870
126979
|
;// ./src/lib/p2p.ts
|
|
126871
126980
|
/* provided dependency */ var client_p2p_Buffer = __webpack_require__(8287)["Buffer"];
|
|
@@ -127583,6 +127692,8 @@ var client_localNode = /*#__PURE__*/new WeakMap();
|
|
|
127583
127692
|
var client_manualPeersCheckIntervals = /*#__PURE__*/new WeakMap();
|
|
127584
127693
|
var client_asyncSends = /*#__PURE__*/new WeakMap();
|
|
127585
127694
|
var client_messageFilterCache = /*#__PURE__*/new WeakMap();
|
|
127695
|
+
var client_cachedLocalPeerInfo = /*#__PURE__*/new WeakMap();
|
|
127696
|
+
var client_cachedLocalPeerSerialized = /*#__PURE__*/new WeakMap();
|
|
127586
127697
|
var client_P2PSwitch_brand = /*#__PURE__*/new WeakSet();
|
|
127587
127698
|
var client_peersCacheSet = /*#__PURE__*/new WeakMap();
|
|
127588
127699
|
class src_client_P2PSwitch {
|
|
@@ -127618,6 +127729,8 @@ class src_client_P2PSwitch {
|
|
|
127618
127729
|
client_p2p_classPrivateFieldInitSpec(this, client_manualPeersCheckIntervals, void 0);
|
|
127619
127730
|
client_p2p_classPrivateFieldInitSpec(this, client_asyncSends, []);
|
|
127620
127731
|
client_p2p_classPrivateFieldInitSpec(this, client_messageFilterCache, {});
|
|
127732
|
+
client_p2p_classPrivateFieldInitSpec(this, client_cachedLocalPeerInfo, undefined);
|
|
127733
|
+
client_p2p_classPrivateFieldInitSpec(this, client_cachedLocalPeerSerialized, undefined);
|
|
127621
127734
|
/**
|
|
127622
127735
|
* Write a debug or error message to the connected node.
|
|
127623
127736
|
*
|
|
@@ -127962,11 +128075,14 @@ class src_client_P2PSwitch {
|
|
|
127962
128075
|
return await client_p2p_assertClassBrand(client_P2PSwitch_brand, this, client_getLocalPeerInfo).call(this);
|
|
127963
128076
|
}
|
|
127964
128077
|
async getOutgoingGreetingInfo() {
|
|
127965
|
-
|
|
127966
|
-
|
|
127967
|
-
|
|
128078
|
+
if (client_p2p_classPrivateFieldGet(client_cachedLocalPeerSerialized, this) === undefined) {
|
|
128079
|
+
const greetingInfo = await client_p2p_assertClassBrand(client_P2PSwitch_brand, this, client_getLocalPeerInfo).call(this);
|
|
128080
|
+
if (greetingInfo === null) {
|
|
128081
|
+
throw new Error('Invalid NodeKind for emitting outgoing greeting');
|
|
128082
|
+
}
|
|
128083
|
+
client_p2p_classPrivateFieldSet(client_cachedLocalPeerSerialized, this, client_P2PPeerToJSO(greetingInfo));
|
|
127968
128084
|
}
|
|
127969
|
-
return
|
|
128085
|
+
return client_p2p_classPrivateFieldGet(client_cachedLocalPeerSerialized, this);
|
|
127970
128086
|
}
|
|
127971
128087
|
/**
|
|
127972
128088
|
* Receive a message from a connection
|
|
@@ -128655,47 +128771,50 @@ async function client_performPeerCleanup() {
|
|
|
128655
128771
|
/** XXX:TODO */
|
|
128656
128772
|
}
|
|
128657
128773
|
async function client_getLocalPeerInfo() {
|
|
128658
|
-
|
|
128659
|
-
|
|
128660
|
-
|
|
128661
|
-
|
|
128662
|
-
|
|
128663
|
-
id: 'unused'
|
|
128664
|
-
};
|
|
128665
|
-
break;
|
|
128666
|
-
case client_node_NodeKind.REPRESENTATIVE:
|
|
128667
|
-
{
|
|
128668
|
-
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints === undefined) {
|
|
128669
|
-
throw new Error('internal error: Our endpoints are not defined');
|
|
128670
|
-
}
|
|
128671
|
-
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.p2p === undefined) {
|
|
128672
|
-
throw new Error('internal error: Our endpoint (p2p) is not defined');
|
|
128673
|
-
}
|
|
128674
|
-
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.api === undefined) {
|
|
128675
|
-
throw new Error('internal error: Our endpoint (api) is not defined');
|
|
128676
|
-
}
|
|
128677
|
-
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.ledgerPrivateKey === undefined) {
|
|
128678
|
-
throw new Error('internal error: Our ledger key is not defined');
|
|
128679
|
-
}
|
|
128680
|
-
const greetingInfoSigned = await client_generateP2PPeerSigned({
|
|
128774
|
+
if (client_p2p_classPrivateFieldGet(client_cachedLocalPeerInfo, this) === undefined) {
|
|
128775
|
+
let greetingInfo;
|
|
128776
|
+
switch (client_p2p_classPrivateFieldGet(client_localNode, this).config.kind) {
|
|
128777
|
+
case client_node_NodeKind.PARTICIPANT:
|
|
128778
|
+
greetingInfo = {
|
|
128681
128779
|
kind: client_p2p_classPrivateFieldGet(client_localNode, this).config.kind,
|
|
128682
|
-
|
|
128683
|
-
|
|
128684
|
-
p2p: client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.p2p,
|
|
128685
|
-
api: client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.api
|
|
128686
|
-
},
|
|
128687
|
-
preferUpdates: this.config.useHTTPRepublish ? 'http' : 'websocket'
|
|
128688
|
-
});
|
|
128689
|
-
if (greetingInfoSigned === null) {
|
|
128690
|
-
throw new Error('internal error: Could not generate signature');
|
|
128691
|
-
}
|
|
128692
|
-
greetingInfo = greetingInfoSigned;
|
|
128780
|
+
id: 'unused'
|
|
128781
|
+
};
|
|
128693
128782
|
break;
|
|
128694
|
-
|
|
128695
|
-
|
|
128696
|
-
|
|
128783
|
+
case client_node_NodeKind.REPRESENTATIVE:
|
|
128784
|
+
{
|
|
128785
|
+
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints === undefined) {
|
|
128786
|
+
throw new Error('internal error: Our endpoints are not defined');
|
|
128787
|
+
}
|
|
128788
|
+
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.p2p === undefined) {
|
|
128789
|
+
throw new Error('internal error: Our endpoint (p2p) is not defined');
|
|
128790
|
+
}
|
|
128791
|
+
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.api === undefined) {
|
|
128792
|
+
throw new Error('internal error: Our endpoint (api) is not defined');
|
|
128793
|
+
}
|
|
128794
|
+
if (client_p2p_classPrivateFieldGet(client_localNode, this).config.ledgerPrivateKey === undefined) {
|
|
128795
|
+
throw new Error('internal error: Our ledger key is not defined');
|
|
128796
|
+
}
|
|
128797
|
+
const greetingInfoSigned = await client_generateP2PPeerSigned({
|
|
128798
|
+
kind: client_p2p_classPrivateFieldGet(client_localNode, this).config.kind,
|
|
128799
|
+
key: client_p2p_classPrivateFieldGet(client_localNode, this).config.ledgerPrivateKey,
|
|
128800
|
+
endpoints: {
|
|
128801
|
+
p2p: client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.p2p,
|
|
128802
|
+
api: client_p2p_classPrivateFieldGet(client_localNode, this).config.endpoints.api
|
|
128803
|
+
},
|
|
128804
|
+
preferUpdates: this.config.useHTTPRepublish ? 'http' : 'websocket'
|
|
128805
|
+
});
|
|
128806
|
+
if (greetingInfoSigned === null) {
|
|
128807
|
+
throw new Error('internal error: Could not generate signature');
|
|
128808
|
+
}
|
|
128809
|
+
greetingInfo = greetingInfoSigned;
|
|
128810
|
+
break;
|
|
128811
|
+
}
|
|
128812
|
+
default:
|
|
128813
|
+
return null;
|
|
128814
|
+
}
|
|
128815
|
+
client_p2p_classPrivateFieldSet(client_cachedLocalPeerInfo, this, greetingInfo);
|
|
128697
128816
|
}
|
|
128698
|
-
return
|
|
128817
|
+
return client_p2p_classPrivateFieldGet(client_cachedLocalPeerInfo, this);
|
|
128699
128818
|
}
|
|
128700
128819
|
async function client_emitOutgoingGreeting(to) {
|
|
128701
128820
|
const messageID = client_esm_browser_v4();
|
|
@@ -129353,9 +129472,18 @@ function client_builder_assertClassBrand(e, t, n) { if ("function" == typeof e ?
|
|
|
129353
129472
|
|
|
129354
129473
|
|
|
129355
129474
|
|
|
129475
|
+
/** @expand */
|
|
129476
|
+
|
|
129356
129477
|
/** @expandType GetPrevFunction */
|
|
129357
129478
|
|
|
129358
|
-
/** @
|
|
129479
|
+
/** @expand */
|
|
129480
|
+
|
|
129481
|
+
/*
|
|
129482
|
+
* Ensure that BlockBuilderOptions is exactly the same as
|
|
129483
|
+
* Partial<AccountSignerOptions> -- we do this so that the
|
|
129484
|
+
* documentation gets generated correctly, otherwise it
|
|
129485
|
+
* gets confused by `Partial`
|
|
129486
|
+
*/
|
|
129359
129487
|
|
|
129360
129488
|
/**
|
|
129361
129489
|
* Either a UserClient or an object with a client and network
|
|
@@ -131987,6 +132115,7 @@ function client_parseAccountInfo(account, accountInfo) {
|
|
|
131987
132115
|
return {
|
|
131988
132116
|
account: client_src_lib.Account.fromPublicKeyString(accountInfo.account),
|
|
131989
132117
|
currentHeadBlock: currentHeadBlock,
|
|
132118
|
+
currentHeadBlockHeight: accountInfo.currentHeadBlockHeight,
|
|
131990
132119
|
representative: currentRepresentative,
|
|
131991
132120
|
info: client_client_assertClassBrand(client_Client_brand, this, client_formatAccountInfo).call(this, accountInfo.info),
|
|
131992
132121
|
balances: client_client_assertClassBrand(client_Client_brand, this, client_formatAllBalances).call(this, accountInfo.balances)
|