Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Updates CcmTransferEvent & CrossChainTransferCommand (#9011)
Browse files Browse the repository at this point in the history
Updates CcmTransferEvent with sending and receiving chain and CrossChainTransferCommand.execute to charge fee if CMM status is not OK

Co-authored-by: Incede <[email protected]>
  • Loading branch information
has5aan and Incede authored Sep 21, 2023
1 parent 4a3fd2a commit cf5c582
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
7 changes: 6 additions & 1 deletion framework/src/modules/nft/cc_commands/cc_transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ export class CrossChainTransferCommand extends BaseCCCommand {
senderAddress,
recipientAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
},
NftEventResult.RESULT_NFT_NOT_SUPPORTED,
);
throw new Error('Non-supported NFT');
}
this._feeMethod.payFee(getMethodContext(), BigInt(FEE_CREATE_NFT));

if (status === CCM_STATUS_CODE_OK) {
this._feeMethod.payFee(getMethodContext(), BigInt(FEE_CREATE_NFT));
await nftStore.save(getMethodContext(), nftID, {
owner: recipientAddress,
attributesArray: receivedAttributes as NFTAttributes[],
Expand All @@ -157,6 +160,8 @@ export class CrossChainTransferCommand extends BaseCCCommand {
senderAddress,
recipientAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
});
}
}
27 changes: 24 additions & 3 deletions framework/src/modules/nft/events/ccm_transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@
*/

import { BaseEvent, EventQueuer } from '../../base_event';
import { LENGTH_NFT_ID, NftEventResult } from '../constants';
import { LENGTH_CHAIN_ID, LENGTH_NFT_ID, NftEventResult } from '../constants';

export interface CCMTransferEventData {
senderAddress: Buffer;
recipientAddress: Buffer;
nftID: Buffer;
receivingChainID: Buffer;
sendingChainID: Buffer;
}

export const ccmTransferEventSchema = {
$id: '/nft/events/ccmTransfer',
type: 'object',
required: ['senderAddress', 'recipientAddress', 'nftID', 'result'],
required: [
'senderAddress',
'recipientAddress',
'nftID',
'receivingChainID',
'sendingChainID',
'result',
],
properties: {
senderAddress: {
dataType: 'bytes',
Expand All @@ -42,9 +51,21 @@ export const ccmTransferEventSchema = {
maxLength: LENGTH_NFT_ID,
fieldNumber: 3,
},
receivingChainID: {
dataType: 'bytes',
minLength: LENGTH_CHAIN_ID,
maxLength: LENGTH_CHAIN_ID,
fieldNumber: 4,
},
sendingChainID: {
dataType: 'bytes',
minLength: LENGTH_CHAIN_ID,
maxLength: LENGTH_CHAIN_ID,
fieldNumber: 5,
},
result: {
dataType: 'uint32',
fieldNumber: 4,
fieldNumber: 6,
},
},
};
Expand Down
12 changes: 11 additions & 1 deletion framework/test/unit/modules/nft/cc_comands/cc_transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ describe('CrossChain Transfer Command', () => {
senderAddress,
recipientAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
});
});

Expand Down Expand Up @@ -465,6 +467,8 @@ describe('CrossChain Transfer Command', () => {
senderAddress,
recipientAddress: senderAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
});
});

Expand Down Expand Up @@ -514,6 +518,8 @@ describe('CrossChain Transfer Command', () => {
senderAddress,
recipientAddress,
nftID: newNftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
},
NftEventResult.RESULT_NFT_NOT_SUPPORTED,
);
Expand Down Expand Up @@ -560,6 +566,8 @@ describe('CrossChain Transfer Command', () => {
senderAddress,
recipientAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
});
});

Expand Down Expand Up @@ -610,7 +618,7 @@ describe('CrossChain Transfer Command', () => {
methodContext,
userStore.getKey(senderAddress, nftID),
);
expect(feeMethod.payFee).not.toHaveBeenCalled();
expect(feeMethod.payFee).toHaveBeenCalledWith(methodContext, BigInt(FEE_CREATE_NFT));
expect(nftStoreData.owner).toStrictEqual(senderAddress);
expect(nftStoreData.attributesArray).toEqual(attributesArray);
expect(userAccountExistsForRecipient).toBe(false);
Expand All @@ -619,6 +627,8 @@ describe('CrossChain Transfer Command', () => {
senderAddress,
recipientAddress: senderAddress,
nftID,
receivingChainID: ccm.receivingChainID,
sendingChainID: ccm.sendingChainID,
});
});
});
Expand Down

0 comments on commit cf5c582

Please sign in to comment.