@rosen-chains/cardano
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -5,3 +5,3 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; | ||
import { TokenMap } from '@rosen-bridge/tokens'; | ||
import { AbstractUtxoChain, BoxInfo, ConfirmationStatus, EventTrigger, PaymentOrder, PaymentTransaction, SigningStatus, TransactionAssetBalance } from '@rosen-chains/abstract-chain'; | ||
import { AbstractUtxoChain, BoxInfo, ConfirmationStatus, EventTrigger, PaymentOrder, PaymentTransaction, SigningStatus, TransactionAssetBalance, TransactionType } from '@rosen-chains/abstract-chain'; | ||
import AbstractCardanoNetwork from './network/AbstractCardanoNetwork'; | ||
@@ -31,3 +31,3 @@ import { CardanoConfigs, CardanoUtxo } from './types'; | ||
*/ | ||
generateTransaction: (eventId: string, txType: string, order: PaymentOrder, unsignedTransactions: PaymentTransaction[], serializedSignedTransactions: string[]) => Promise<PaymentTransaction>; | ||
generateTransaction: (eventId: string, txType: TransactionType, order: PaymentOrder, unsignedTransactions: PaymentTransaction[], serializedSignedTransactions: string[]) => Promise<PaymentTransaction>; | ||
/** | ||
@@ -103,3 +103,3 @@ * extracts box id and assets of a box | ||
*/ | ||
getTxConfirmationStatus: (transactionId: string, transactionType: string) => Promise<ConfirmationStatus>; | ||
getTxConfirmationStatus: (transactionId: string, transactionType: TransactionType) => Promise<ConfirmationStatus>; | ||
/** | ||
@@ -106,0 +106,0 @@ * gets the minimum amount of native token for assetTransfer |
@@ -1,2 +0,2 @@ | ||
import { PaymentTransaction } from '@rosen-chains/abstract-chain'; | ||
import { PaymentTransaction, TransactionType } from '@rosen-chains/abstract-chain'; | ||
declare class CardanoTransaction implements PaymentTransaction { | ||
@@ -7,4 +7,4 @@ eventId: string; | ||
txId: string; | ||
txType: string; | ||
constructor(eventId: string, txBytes: Uint8Array, txId: string, txType: string); | ||
txType: TransactionType; | ||
constructor(eventId: string, txBytes: Uint8Array, txId: string, txType: TransactionType); | ||
/** | ||
@@ -11,0 +11,0 @@ * converts json representation of the payment transaction to CardanoTransaction |
@@ -44,2 +44,2 @@ import { CARDANO_CHAIN } from './constants'; | ||
export default CardanoTransaction; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FyZGFub1RyYW5zYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vbGliL0NhcmRhbm9UcmFuc2FjdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRzVDLE1BQU0sa0JBQWtCO0lBQ3RCLE9BQU8sQ0FBUztJQUNoQixPQUFPLENBQVM7SUFDaEIsT0FBTyxDQUFhO0lBQ3BCLElBQUksQ0FBUztJQUNiLE1BQU0sQ0FBUztJQUVmLFlBQ0UsT0FBZSxFQUNmLE9BQW1CLEVBQ25CLElBQVksRUFDWixNQUFjO1FBRWQsSUFBSSxDQUFDLE9BQU8sR0FBRyxhQUFhLENBQUM7UUFDN0IsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7UUFDdkIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7UUFDdkIsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7UUFDakIsSUFBSSxDQUFDLE1BQU0sR0FBRyxNQUFNLENBQUM7SUFDdkIsQ0FBQztJQUVEOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxRQUFRLEdBQUcsQ0FBQyxVQUFrQixFQUFzQixFQUFFO1FBQzNELE1BQU0sR0FBRyxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDbkMsT0FBTyxJQUFJLGtCQUFrQixDQUMzQixHQUFHLENBQUMsT0FBTyxFQUNYLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sRUFBRSxLQU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ogc3RyaW5nKTogQ2FyZGFub1RyYW5zYWN0aW9uID0+IHtcbiAgICBjb25zdCBvYmogPSBKU09OLnBhcnNlKGpzb25TdHJpbmcpIGFzIFBheW1lbnRUcmFuc2FjdGlvbkpzb25Nb2RlbDtcbiAgICByZXR1cm4gbmV3IENhcmRhbm9UcmFuc2FjdGlvbihcbiAgICAgIG9iai5ldmVudElkLFxuICAgICAgQnVmZmVyLmZyb20ob2JqLnR4Qnl0ZXMsICdoZXgnKSxcbiAgICAgIG9iai50eElkLFxuICAgICAgb2JqLnR4VHlwZSBhcyBUcmFuc2FjdGlvblR5cGVcbiAgICApO1xuICB9O1xuXG4gIC8qKlxuICAgKiBjb252ZXJ0cyBDYXJkYW5vVHJhbnNhY3Rpb24gdG8ganNvblxuICAgKiBAcmV0dXJucyBqc29uIHJlcHJlc2VudGF0aW9uIG9mIHRoZSBwYXltZW50IHRyYW5zYWN0aW9uXG4gICAqL1xuICB0b0pzb24gPSAoKTogc3RyaW5nID0+IHtcbiAgICByZXR1cm4gSlNPTi5zdHJpbmdpZnkoe1xuICAgICAgbmV0d29yazogdGhpcy5uZXR3b3JrLFxuICAgICAgZXZlbnRJZDogdGhpcy5ldmVudElkLFxuICAgICAgdHhCeXRlczogdGhpcy5nZXRUeEhleFN0cmluZygpLFxuICAgICAgdHhJZDogdGhpcy50eElkLFxuICAgICAgdHhUeXBlOiB0aGlzLnR4VHlwZSxcbiAgICB9KTtcbiAgfTtcblxuICAvKipcbiAgICogQHJldHVybnMgdHJhbnNhY3Rpb24gaGV4IHN0cmluZ1xuICAgKi9cbiAgZ2V0VHhIZXhTdHJpbmcgPSAoKSA9PiB7XG4gICAgcmV0dXJuIEJ1ZmZlci5mcm9tKHRoaXMudHhCeXRlcykudG9TdHJpbmcoJ2hleCcpO1xuICB9O1xufVxuXG5leHBvcnQgZGVmYXVsdCBDYXJkYW5vVHJhbnNhY3Rpb247XG4iXX0= |
@@ -26,3 +26,3 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; | ||
TransactionAssetBalance, | ||
TransactionTypes, | ||
TransactionType, | ||
UnexpectedApiError, | ||
@@ -105,3 +105,3 @@ } from '@rosen-chains/abstract-chain'; | ||
eventId: string, | ||
txType: string, | ||
txType: TransactionType, | ||
order: PaymentOrder, | ||
@@ -112,9 +112,12 @@ unsignedTransactions: PaymentTransaction[], | ||
// calculate required assets | ||
const orderRequiredAssets = order | ||
const requiredAssets = order | ||
.map((order) => order.assets) | ||
.reduce(ChainUtils.sumAssetBalance, { nativeToken: 0n, tokens: [] }); | ||
.reduce(ChainUtils.sumAssetBalance, { | ||
nativeToken: this.getMinimumNativeToken(), | ||
tokens: [], | ||
}); | ||
if (!(await this.hasLockAddressEnoughAssets(orderRequiredAssets))) { | ||
const neededADA = orderRequiredAssets.nativeToken.toString(); | ||
const neededTokens = JSONBigInt.stringify(orderRequiredAssets.tokens); | ||
if (!(await this.hasLockAddressEnoughAssets(requiredAssets))) { | ||
const neededADA = requiredAssets.nativeToken.toString(); | ||
const neededTokens = JSONBigInt.stringify(requiredAssets.tokens); | ||
throw new NotEnoughAssetsError( | ||
@@ -142,3 +145,3 @@ `Locked assets cannot cover required assets. ADA: ${neededADA}, Tokens: ${neededTokens}` | ||
this.configs.lockAddress, | ||
orderRequiredAssets, | ||
requiredAssets, | ||
forbiddenBoxIds, | ||
@@ -148,4 +151,4 @@ trackMap | ||
if (!coveredBoxes.covered) { | ||
const neededAdas = orderRequiredAssets.nativeToken.toString(); | ||
const neededTokens = JSONBigInt.stringify(orderRequiredAssets.tokens); | ||
const neededAdas = requiredAssets.nativeToken.toString(); | ||
const neededTokens = JSONBigInt.stringify(requiredAssets.tokens); | ||
throw new NotEnoughValidBoxesError( | ||
@@ -636,22 +639,8 @@ `Available boxes didn't cover required assets. ADA: ${neededAdas}, Tokens: ${neededTokens}` | ||
transactionId: string, | ||
transactionType: string | ||
transactionType: TransactionType | ||
): Promise<ConfirmationStatus> => { | ||
let expectedConfirmation = 0; | ||
switch (transactionType) { | ||
case TransactionTypes.lock: | ||
expectedConfirmation = this.configs.observationTxConfirmation; | ||
break; | ||
case TransactionTypes.payment: | ||
case TransactionTypes.reward: | ||
expectedConfirmation = this.configs.paymentTxConfirmation; | ||
break; | ||
case TransactionTypes.coldStorage: | ||
expectedConfirmation = this.configs.coldTxConfirmation; | ||
break; | ||
default: | ||
throw new Error(`Transaction type [${transactionType}] is not defined`); | ||
} | ||
const requiredConfirmation = | ||
this.getTxRequiredConfirmation(transactionType); | ||
const confirmation = await this.network.getTxConfirmation(transactionId); | ||
if (confirmation >= expectedConfirmation) | ||
if (confirmation >= requiredConfirmation) | ||
return ConfirmationStatus.ConfirmedEnough; | ||
@@ -658,0 +647,0 @@ else if (confirmation === -1) return ConfirmationStatus.NotFound; |
@@ -1,4 +0,7 @@ | ||
import { PaymentTransaction } from '@rosen-chains/abstract-chain'; | ||
import { | ||
PaymentTransaction, | ||
PaymentTransactionJsonModel, | ||
TransactionType, | ||
} from '@rosen-chains/abstract-chain'; | ||
import { CARDANO_CHAIN } from './constants'; | ||
import * as JSONBigInt from 'json-bigint'; | ||
@@ -10,3 +13,3 @@ class CardanoTransaction implements PaymentTransaction { | ||
txId: string; | ||
txType: string; | ||
txType: TransactionType; | ||
@@ -17,3 +20,3 @@ constructor( | ||
txId: string, | ||
txType: string | ||
txType: TransactionType | ||
) { | ||
@@ -32,3 +35,3 @@ this.network = CARDANO_CHAIN; | ||
static fromJson = (jsonString: string): CardanoTransaction => { | ||
const obj = JSON.parse(jsonString); | ||
const obj = JSON.parse(jsonString) as PaymentTransactionJsonModel; | ||
return new CardanoTransaction( | ||
@@ -38,3 +41,3 @@ obj.eventId, | ||
obj.txId, | ||
obj.txType | ||
obj.txType as TransactionType | ||
); | ||
@@ -41,0 +44,0 @@ }; |
{ | ||
"name": "@rosen-chains/cardano", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "this project contains cardano chain for Rosen-bridge", | ||
@@ -26,3 +26,3 @@ "main": "dist/lib/index.js", | ||
"@rosen-bridge/rosen-extractor": "^0.1.8", | ||
"@rosen-chains/abstract-chain": "^0.1.12", | ||
"@rosen-chains/abstract-chain": "^0.1.13", | ||
"bech32": "^2.0.0", | ||
@@ -29,0 +29,0 @@ "blake2b": "^2.1.3", |
@@ -14,3 +14,3 @@ import { RosenTokens, TokenMap } from '@rosen-bridge/tokens'; | ||
NotEnoughValidBoxesError, | ||
TransactionTypes, | ||
TransactionType, | ||
} from '@rosen-chains/abstract-chain'; | ||
@@ -31,8 +31,10 @@ import { Fee } from '@rosen-bridge/minimum-fee'; | ||
const coldTxConfirmation = 10; | ||
const manualTxConfirmation = 11; | ||
const rwtId = | ||
'9410db5b39388c6b515160e7248346d7ec63d5457292326da12a26cc02efb526'; | ||
const feeRationDivisor = 1n; | ||
const minBoxValue = 2000000n; | ||
const configs: CardanoConfigs = { | ||
fee: 1000000n, | ||
minBoxValue: 2000000n, | ||
minBoxValue: minBoxValue, | ||
txTtl: 64, | ||
@@ -43,5 +45,8 @@ lockAddress: | ||
rwtId: rwtId, | ||
coldTxConfirmation: coldTxConfirmation, | ||
paymentTxConfirmation: paymentTxConfirmation, | ||
observationTxConfirmation: observationTxConfirmation, | ||
confirmations: { | ||
observation: observationTxConfirmation, | ||
payment: paymentTxConfirmation, | ||
cold: coldTxConfirmation, | ||
manual: manualTxConfirmation, | ||
}, | ||
aggregatedPublicKey: | ||
@@ -138,5 +143,9 @@ 'bcb07faa6c0f19e2f2587aa9ef6f43a68fc0135321216a71dc87c8527af4ca6a', | ||
// getCoveringBoxes should have been called with correct arguments | ||
const expectedRequiredAssets = structuredClone( | ||
TestData.transaction1Order[0].assets | ||
); | ||
expectedRequiredAssets.nativeToken += minBoxValue; | ||
expect(getCovBoxesSpy).toHaveBeenCalledWith( | ||
configs.lockAddress, | ||
TestData.transaction1Order[0].assets, | ||
expectedRequiredAssets, | ||
TestData.transaction1InputIds, | ||
@@ -189,3 +198,3 @@ new Map() | ||
'2bedc6e54ede7748e5efc7df689a0a89b281ac1d92d09054650d5f27a25d5b85', | ||
'payment', | ||
TransactionType.payment, | ||
order, | ||
@@ -240,3 +249,3 @@ [], | ||
'event1', | ||
'type1', | ||
TransactionType.payment, | ||
TestData.transaction1Order, | ||
@@ -277,3 +286,3 @@ [], | ||
'event1', | ||
'type1', | ||
TransactionType.payment, | ||
TestData.transaction1Order, | ||
@@ -930,17 +939,8 @@ [], | ||
describe('getTxConfirmationStatus', () => { | ||
/** | ||
* gets test confirmation config for a transaction by type | ||
* @param type | ||
*/ | ||
const getConfigConfirmation = (type: string): number => { | ||
if (type === TransactionTypes.payment) return paymentTxConfirmation; | ||
else if (type === TransactionTypes.reward) return paymentTxConfirmation; | ||
else if (type === TransactionTypes.coldStorage) return coldTxConfirmation; | ||
else if (type === TransactionTypes.lock) return observationTxConfirmation; | ||
else throw new Error(`Transaction type [${type}] is not defined`); | ||
}; | ||
const txType = TransactionType.payment; | ||
const requiredConfirmation = paymentTxConfirmation; | ||
/** | ||
* @target CardanoChain.getTxConfirmationStatus should return | ||
* ConfirmedEnough when tx confirmation is more than expected config | ||
* ConfirmedEnough when tx confirmation is more than required number | ||
* @dependencies | ||
@@ -955,32 +955,24 @@ * @scenario | ||
*/ | ||
it.each([ | ||
TransactionTypes.payment, | ||
TransactionTypes.reward, | ||
TransactionTypes.coldStorage, | ||
TransactionTypes.lock, | ||
])( | ||
'should return ConfirmedEnough when %p tx confirmation is more than expected config', | ||
async (txType: string) => { | ||
// generate a random txId | ||
const txId = TestUtils.generateRandomId(); | ||
it('should return ConfirmedEnough when tx confirmation is more than required number', async () => { | ||
// generate a random txId | ||
const txId = TestUtils.generateRandomId(); | ||
// mock a network object to return enough confirmation for mocked txId | ||
const network = new TestCardanoNetwork(); | ||
const getTxConfirmationSpy = spyOn(network, 'getTxConfirmation'); | ||
when(getTxConfirmationSpy) | ||
.calledWith(txId) | ||
.mockResolvedValueOnce(getConfigConfirmation(txType)); | ||
// mock a network object to return enough confirmation for mocked txId | ||
const network = new TestCardanoNetwork(); | ||
const getTxConfirmationSpy = spyOn(network, 'getTxConfirmation'); | ||
when(getTxConfirmationSpy) | ||
.calledWith(txId) | ||
.mockResolvedValueOnce(requiredConfirmation + 1); | ||
// call the function | ||
const cardanoChain = generateChainObject(network); | ||
const result = await cardanoChain.getTxConfirmationStatus(txId, txType); | ||
// call the function | ||
const cardanoChain = generateChainObject(network); | ||
const result = await cardanoChain.getTxConfirmationStatus(txId, txType); | ||
// check returned value | ||
expect(result).toEqual(ConfirmationStatus.ConfirmedEnough); | ||
} | ||
); | ||
// check returned value | ||
expect(result).toEqual(ConfirmationStatus.ConfirmedEnough); | ||
}); | ||
/** | ||
* @target CardanoChain.getTxConfirmationStatus should return | ||
* NotConfirmedEnough when payment tx confirmation is less than expected config | ||
* NotConfirmedEnough when payment tx confirmation is less than required number | ||
* @dependencies | ||
@@ -996,28 +988,20 @@ * @scenario | ||
*/ | ||
it.each([ | ||
TransactionTypes.payment, | ||
TransactionTypes.reward, | ||
TransactionTypes.coldStorage, | ||
TransactionTypes.lock, | ||
])( | ||
'should return NotConfirmedEnough when %p tx confirmation is less than expected config', | ||
async (txType: string) => { | ||
// generate a random txId | ||
const txId = TestUtils.generateRandomId(); | ||
it('should return NotConfirmedEnough when tx confirmation is less than required number', async () => { | ||
// generate a random txId | ||
const txId = TestUtils.generateRandomId(); | ||
// mock a network object to return insufficient confirmation for mocked txId | ||
const network = new TestCardanoNetwork(); | ||
const getTxConfirmationSpy = spyOn(network, 'getTxConfirmation'); | ||
when(getTxConfirmationSpy) | ||
.calledWith(txId) | ||
.mockResolvedValueOnce(getConfigConfirmation(txType) - 1); | ||
// mock a network object to return insufficient confirmation for mocked txId | ||
const network = new TestCardanoNetwork(); | ||
const getTxConfirmationSpy = spyOn(network, 'getTxConfirmation'); | ||
when(getTxConfirmationSpy) | ||
.calledWith(txId) | ||
.mockResolvedValueOnce(requiredConfirmation - 1); | ||
// call the function | ||
const cardanoChain = generateChainObject(network); | ||
const result = await cardanoChain.getTxConfirmationStatus(txId, txType); | ||
// call the function | ||
const cardanoChain = generateChainObject(network); | ||
const result = await cardanoChain.getTxConfirmationStatus(txId, txType); | ||
// check returned value | ||
expect(result).toEqual(ConfirmationStatus.NotConfirmedEnough); | ||
} | ||
); | ||
// check returned value | ||
expect(result).toEqual(ConfirmationStatus.NotConfirmedEnough); | ||
}); | ||
@@ -1047,6 +1031,3 @@ /** | ||
const cardanoChain = generateChainObject(network); | ||
const result = await cardanoChain.getTxConfirmationStatus( | ||
txId, | ||
TransactionTypes.payment | ||
); | ||
const result = await cardanoChain.getTxConfirmationStatus(txId, txType); | ||
@@ -1053,0 +1034,0 @@ // check returned value |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
290236
4082
+ Addedaxios@1.7.8(transitive)
- Removedaxios@1.7.7(transitive)