Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk/javascript] sending transaction - error for unordered mosaics array #206

Closed
cryptoBeliever opened this issue May 6, 2022 · 2 comments · Fixed by #295
Closed

[sdk/javascript] sending transaction - error for unordered mosaics array #206

cryptoBeliever opened this issue May 6, 2022 · 2 comments · Fixed by #295
Assignees
Labels
sdk-javascript Related to the Javascript SDK. Status: WIP This issue or PR is a work in progress.

Comments

@cryptoBeliever
Copy link
Contributor

cryptoBeliever commented May 6, 2022

When a mosaic array is not ordered by mosaic_id when constructing a transaction we get the error: "array passed to write array is not sorted". SDK should handle sorting and not require to sort it by the developer which is using SDK.

Example code causing the error:

const transaction = facade.transactionFactory.create({
		type: 'transfer_transaction',
		signerPublicKey: keyPair.publicKey.toString(),
		recipientAddress: recipientAddress,
		fee: 0n,
		deadline: getDeadline(),
		mosaics: [
			{
				mosaicId: BigInt('0x6BED913FA20223F8'),
				amount: BigInt(amountInAtomicUnit)
			},{
				mosaicId: BigInt('0x170B5916F65E13DC'),
				amount: BigInt(amountInAtomicUnit)
			}
		]
	});

Result:
Error:

(node:83507) UnhandledPromiseRejectionWarning: RangeError: array passed to write array is not sorted
    at writeArrayImpl (/home/comp/Developer/git/example2/node_modules/symbol-sdk/src/utils/arrayHelpers.js:31:10)
    at Object.writeArray (/home/comp/Developer/git/example2/node_modules/symbol-sdk/src/utils/arrayHelpers.js:126:3)
    at TransferTransaction.serialize (/home/comp/Developer/git/example2/node_modules/symbol-sdk/src/symbol/models.js:11176:16)
    at SymbolFacade.signTransaction (/home/comp/Developer/git/example2/node_modules/symbol-sdk/src/facade/SymbolFacade.js:89:41)

Expected result:
SDK should handle sorting of mosaic array internally (if it's required to serialize sorted).

Used SDK version: 3.0.0

Corresponding issue for Python SDK: #205

@cryptoBeliever cryptoBeliever added Status: WIP This issue or PR is a work in progress. sdk-javascript Related to the Javascript SDK. labels May 6, 2022
Jaguar0625 added a commit that referenced this issue Jul 7, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Jul 8, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Jul 27, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 2, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 2, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
Jaguar0625 added a commit that referenced this issue Sep 9, 2022
 problem: currently user is expected to manually sort all ordered arrays in transaction descriptors
solution: provide autosort option on create (the default) to automatically sort the arrays during creation
   issue: #206
@gimre-xymcity
Copy link
Member

auto-sorting for create() is now default behavior, js sdk 3.0.4

@cryptoBeliever
Copy link
Contributor Author

cryptoBeliever commented Apr 9, 2023

Works correctly with unordered mosaics list. Example tx:

const transaction = facade.transactionFactory.create({
        type: 'transfer_transaction_v1',
        signerPublicKey: keyPair.publicKey.toString(),
        recipientAddress: 'TCJVHYTL32T4KOHSU55I6EPLWMAJCFXRNRCVJXA',
        fee: 100000n,
        deadline: BigInt(timestamp + 3600n * 1000n), // 3600sec * 1000ms
        mosaics: [
            {
                mosaicId: BigInt('0x3B6C1884BB157E22'),
                amount: BigInt(100)
            },
            {
                mosaicId: BigInt('0x11A883250997A39A'),
                amount: BigInt(100)
            }
        ],
        message: '\0'+'some message' // 0 is message type - plain text
    });

https://testnet.symbol.fyi/transactions/1D69D06D347A42EEB94DD7FCF4A5C515993607215190446E972A717E0D987291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk-javascript Related to the Javascript SDK. Status: WIP This issue or PR is a work in progress.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@Jaguar0625 @gimre-xymcity @cryptoBeliever and others