Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
({ type, value }): PersistenceAdapterBatch => {
switch (type) {
case PersistenceBatchTypes.deleteBundle:
return {
type: PersistenceAdapterBatchTypes.write,
key: tritsToBytes(bundle(value)),
value: tritsToBytes(value),
}
case PersistenceBatchTypes.deleteCDA:
return {
type: PersistenceAdapterBatchTypes.write,
key: tritsToBytes(CDAddress(value)),
value: tritsToBytes(value),
}
}
/* istanbul ignore next */
return undefined as any
}
)
getLatestInclusion(pastAttachmentHashes).tap(inclusionStates => {
if (inclusionStates.indexOf(true) > -1) {
return persistence.del(['0', tritsToTrytes(bundleHash(bundle))].join(':'))
}
return Promise.all(pastAttachmentHashes.map(h => getConsistency([h]))).tap(consistencyStates =>
consistencyStates.indexOf(true) > -1
? setTimeout(() => bundles.write(bundle), delay)
: getTransactionsToApprove(depth, reference ? reference.hash : undefined)
.tap(transactionsToApprove =>
this.emit(Events.getTransactionsToApprove, {
trytes: bundleTritsToBundleTrytes(bundle),
transactionsToApprove,
})
)
.then(
({
trunkTransaction,
branchTransaction,
.then(() => state.delete(tritsToBytes(bundle(buffer))))
.tap(() => this.emit(PersistenceEvents.deleteBundle, buffer))
public addSignature(bundle: Int8Array, inputAddress: string, keyTrits: Int8Array, callback: Callback) {
const bundleHashTrits = bundleHash(bundle)
const normalizedBundleHash = normalizedBundle(bundleHashTrits)
let signatureIndex = 0
for (const offset = 0; offset < bundle.length * TRANSACTION_LENGTH; offset + TRANSACTION_LENGTH) {
if (tritsToTrytes(address(bundle)) === inputAddress && isNinesTrytes(signatureOrMessage(bundle))) {
const signature = new Int8Array(keyTrits.length)
for (let i = 0; i < keyTrits.length / FRAGMENT_LENGTH; i++) {
signature.set(
signatureFragment(
normalizedBundleHash.slice(
i * NORMALIZED_FRAGMENT_LENGTH,
(i + 1) * NORMALIZED_FRAGMENT_LENGTH
),
keyTrits.slice(i * FRAGMENT_LENGTH, (i + 1) * FRAGMENT_LENGTH)
),
...state.withdrawals.map(withdrawal => {
const trits = new Int8Array(withdrawal.length * TRANSACTION_LENGTH)
for (let i = 0; i < withdrawal.length; i++) {
trits.set(trytesToTrits(withdrawal[i]), i * TRANSACTION_LENGTH)
}
return {
type: PersistenceBatchTypes.put,
key: ['0', ':', tritsToTrytes(bundleHash(trits))].join(''),
value: trits,
}
}),
] as PersistenceBatch)
.then(trytes => {
const bundleTrits = bundleTrytesToBundleTrits(trytes)
return persistence.put(
['0', tritsToTrytes(bundleHash(bundleTrits))].join(':'),
bundleTrits
)
})
.then(() => cda)
trytes =>
tritsToTrytes(bundleHash(bundle)) ===
trytes.slice(
BUNDLE_OFFSET / TRYTE_WIDTH,
BUNDLE_OFFSET / TRYTE_WIDTH + BUNDLE_LENGTH / TRYTE_WIDTH
)
)
.tap(trytes =>
persistence.batch([
...inputs.map(
(input): PersistencePutCommand => ({
type: PersistenceBatchTypes.put,
key: ['0', tritsToTrytes(input.address)].join(':'),
value: new Int8Array(1),
})
),
{
type: PersistenceBatchTypes.put,
key: [
'0',
tritsToTrytes(bundleHash(bundleTrytesToBundleTrits(trytes))),
].join(':'),
value: bundleTrytesToBundleTrits(trytes),
},
{
type: PersistenceBatchTypes.put,
key: [SENT_TO_ADDRESS_PREFIX, noChecksum(cdaTransfer.address)].join(
':'
),
value: valueToTrits(cdaTransfer.timeoutAt),
},
])
)