-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: returning correct ledger id in tokeninfo (#163) #222
base: main
Are you sure you want to change the base?
Changes from all commits
05905ed
8f0580f
94819e8
021ef4b
bf16abf
1540e50
714a5b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,19 @@ const { | |
storageLayout: { storage, types }, | ||
} = require('../out/HtsSystemContract.sol/HtsSystemContract.json'); | ||
|
||
let ledgerId = '0x00'; | ||
acuarica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
acuarica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Sets the `ledgerId` used when retrieving fungible and non-fungible tokens. | ||
* The `ledgerId` depends on the `chainId` of the remote network it is forking from. | ||
* | ||
* @param {number} chainId | ||
*/ | ||
const setLedgerId = chainId => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's export this one from nit: convert to |
||
const chainIdToLedgerIdMap = { 295: '0x00', 296: '0x01', 297: '0x02', 298: '0x03' }; | ||
ledgerId = | ||
chainIdToLedgerIdMap[/**@type{keyof typeof chainIdToLedgerIdMap}*/ (chainId)] || '0x00'; | ||
}; | ||
|
||
/** | ||
* Represents the value in the `SlotMap`. | ||
* This can be either a `string`, or a function that returns a `string`. | ||
|
@@ -227,7 +240,7 @@ function slotMapOf(token) { | |
// token['inherit_account_key'] = ZERO_HEX_32_BYTE; | ||
// token['delegatable_contract_id'] = zeroAddress(); | ||
token['treasury'] = token['treasury_account_id']; | ||
token['ledger_id'] = '0x00'; | ||
token['ledger_id'] = ledgerId; | ||
// Every inner `struct` will be flattened by `visit`, | ||
// so it uses the last part of the field path, _i.e._, `.second`. | ||
token['second'] = `${token['expiry_timestamp']}`; | ||
|
@@ -339,4 +352,4 @@ class PersistentStorageMap { | |
} | ||
} | ||
|
||
module.exports = { packValues, slotMapOf, PersistentStorageMap }; | ||
module.exports = { packValues, slotMapOf, PersistentStorageMap, setLedgerId }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also export |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import
setLedgerId
in therequire('..')
that is above.We should treat exported modules in declated
package.json
as independent. All external used functions/classes/consts should be imported from anindex.js
declared inpackage.json
. This way is easier to consumers to also use the package.