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] Metadata - provide util to calculate delta (xor) value and delta length #297

Closed
cryptoBeliever opened this issue Jul 5, 2022 · 3 comments · Fixed by #299
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 Jul 5, 2022

Current Behaviour

Previous SDK when constructing Metadata (Namespace/Mosaic/Account) Transaction automatically calculated delta value and length based on on-chain metadata value fetched during Transaction creation.

New SDK is not doing network communication but would be nice to provide a helper or other way (additional field?) to provide previous value (which the user has to manually fetch from the network) and new value. It would calculate the correct delta value and delta length to put into the transaction.

Expected Behaviour

Provide util/helper or a way to pass previous value during Metadata Transaction creation. Based on that we could calculate:

  • value (delta)
  • value size
  • value size delta

Python issue: #298

@cryptoBeliever cryptoBeliever added Status: WIP This issue or PR is a work in progress. sdk-javascript Related to the Javascript SDK. labels Jul 5, 2022
Jaguar0625 added a commit that referenced this issue Jul 7, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Jul 8, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Jul 8, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Jul 27, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Aug 2, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Aug 2, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Aug 19, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
Jaguar0625 added a commit that referenced this issue Sep 9, 2022
 problem: user manually has to do XOR
solution: add metadataUpdateValue to simplify
   issue: #297
@gimre-xymcity
Copy link
Member

@Jaguar0625 can we close this one and #298 ?

@gimre-xymcity
Copy link
Member

part of js sdk 3.0.4

@cryptoBeliever
Copy link
Contributor Author

cryptoBeliever commented Apr 10, 2023

Works correctly. I'm able to calculate xor using util ✔️ :

    const textEncoder = new TextEncoder();
    const old_value = textEncoder.encode('some value')
    const new_value = textEncoder.encode('some new value')
    const value_delta = symbolSDK.symbol.metadataUpdateValue(old_value, new_value)

    const metadata = facade.transactionFactory.createEmbedded({
        type: 'account_metadata_transaction_v1',
        signerPublicKey: keyPair.publicKey,
        targetAddress: facade.network.publicKeyToAddress(keyPair.publicKey),
        scopedMetadataKey: 4n,
        value: value_delta,
        valueSizeDelta: new_value.length - old_value.length
    })

    const embedded_transactions = [metadata]
    const merkleHash = SymbolFacade.hashEmbeddedTransactions(embedded_transactions)

    const aggregateTransaction = facade.transactionFactory.create({
        type: 'aggregate_complete_transaction_v2',
        signerPublicKey: keyPair.publicKey,
        fee: 100000n,
        deadline: BigInt(timestamp + 3600n * 1000n), // 3600sec * 1000ms
        transactionsHash: merkleHash,
        transactions: embedded_transactions
    })

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.

3 participants