Skip to content

Commit

Permalink
feat: add serialization of TokenAccount extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhd committed Mar 18, 2024
1 parent c3c2d51 commit 835b980
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 4 deletions.
20 changes: 20 additions & 0 deletions libs/coin-framework/src/serialization/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {

export type FromFamiliyRaw = {
assignFromAccountRaw?: AccountBridge<TransactionCommon>["assignFromAccountRaw"];
assignFromTokenAccountRaw?: AccountBridge<TransactionCommon>["assignFromTokenAccountRaw"];
fromOperationExtraRaw?: AccountBridge<TransactionCommon>["fromOperationExtraRaw"];
};

Expand Down Expand Up @@ -148,6 +149,15 @@ export function fromAccountRaw(rawAccount: AccountRaw, fromRaw?: FromFamiliyRaw)
fromRaw.assignFromAccountRaw(rawAccount, res);
}

if (fromRaw?.assignFromTokenAccountRaw && res.subAccounts) {
res.subAccounts.forEach((subAcc, index) => {
const subAccRaw = subAccountsRaw?.[index];
if (subAcc.type === "TokenAccount" && subAccRaw?.type === "TokenAccountRaw") {
fromRaw.assignFromTokenAccountRaw?.(subAccRaw, subAcc);
}
});
}

if (swapHistory) {
res.swapHistory = swapHistory.map(fromSwapOperationRaw);
}
Expand All @@ -157,6 +167,7 @@ export function fromAccountRaw(rawAccount: AccountRaw, fromRaw?: FromFamiliyRaw)

export type ToFamiliyRaw = {
assignToAccountRaw?: AccountBridge<TransactionCommon>["assignToAccountRaw"];
assignToTokenAccountRaw?: AccountBridge<TransactionCommon>["assignToTokenAccountRaw"];
toOperationExtraRaw?: AccountBridge<TransactionCommon>["toOperationExtraRaw"];
};

Expand Down Expand Up @@ -244,6 +255,15 @@ export function toAccountRaw(account: Account, toFamilyRaw?: ToFamiliyRaw): Acco
toFamilyRaw.assignToAccountRaw(account, res);
}

if (toFamilyRaw?.assignToTokenAccountRaw && res.subAccounts) {
res.subAccounts.forEach((subAccRaw, index) => {
const subAcc = subAccounts?.[index];
if (subAccRaw.type === "TokenAccountRaw" && subAcc?.type === "TokenAccount") {
toFamilyRaw.assignToTokenAccountRaw?.(subAcc, subAccRaw);
}
});
}

if (swapHistory) {
res.swapHistory = swapHistory.map(toSwapOperationRaw);
}
Expand Down
26 changes: 26 additions & 0 deletions libs/ledger-live-common/src/account/serialization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getCryptoCurrencyById, getTokenById, setSupportedCurrencies } from "../currencies";
import { genAccount, genTokenAccount } from "@ledgerhq/coin-framework/mocks/account";
import { toAccountRaw, fromAccountRaw } from "./serialization";
import { setWalletAPIVersion } from "../wallet-api/version";
import { WALLET_API_VERSION } from "../wallet-api/constants";

setWalletAPIVersion(WALLET_API_VERSION);

setSupportedCurrencies(["solana"]);
const Solana = getCryptoCurrencyById("solana");
const USDC = getTokenById("solana/spl/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");

describe("serialization", () => {
test("TokenAccount extra fields should be serialized/deserialized", () => {
const acc: any = genAccount("mocked-account-1", { currency: Solana });
const tokenAcc: any = genTokenAccount(1, acc, USDC);
tokenAcc.state = "initialized";
acc.subAccounts = [tokenAcc];

const accRaw: any = toAccountRaw(acc);
expect(accRaw.subAccounts?.[0]?.state).toBe("initialized");

const deserializedAcc: any = fromAccountRaw(accRaw);
expect(deserializedAcc.subAccounts?.[0]?.state).toBe("initialized");
});
});
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/account/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {

return commonFromAccountRaw(rawAccount, {
assignFromAccountRaw: bridge.assignFromAccountRaw,
assignFromTokenAccountRaw: bridge.assignFromTokenAccountRaw,
fromOperationExtraRaw: bridge.fromOperationExtraRaw,
});
}
Expand All @@ -75,6 +76,7 @@ export function toAccountRaw(account: Account): AccountRaw {

return commonToAccountRaw(account, {
assignToAccountRaw: bridge.assignToAccountRaw,
assignToTokenAccountRaw: bridge.assignToTokenAccountRaw,
toOperationExtraRaw: bridge.toOperationExtraRaw,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ exports[`sortCurrenciesByIds snapshot 1`] = `
"ethereum/erc20/ksm_starter_token",
"ethereum/erc20/aditus",
"ethereum/erc20/ethopt_io",
"solana/spl/SHDWyBxihqiCj6YekG2GUr7wqKLeLAMK1gHZck9pL6y",
"ethereum/erc20/bigboom",
"ethereum/erc20/realchain",
"ethereum/erc20/ink_protocol",
Expand Down Expand Up @@ -13786,5 +13787,98 @@ exports[`sortCurrenciesByIds snapshot 1`] = `
"cardano/native/f7c777fdd4531cf1c477551360e45b9684073c05c2fa61334f8f9add5665726974726565546f6b656e",
"stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
"casper/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
"solana/spl/2VhjJ9WxaGC3EZFwJG9BDUs9KxKCAjQY4vgd1qxgYWVg",
"solana/spl/35r2jMGKytAJ7FyKfKRHPanT8kpjg3emPy7WG6GANCNB",
"solana/spl/3bRTivrVsitbmCTGtqwp7hxXPsybkjn4XLNtPsHqa3zR",
"solana/spl/3dgCCb15HMQSA4Pn3Tfii5vRk7aRqTH95LJjxzsG2Mug",
"solana/spl/4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R",
"solana/spl/4vMsoUT2BWatFweudnQM1xedRLfJgJ7hswhcpz4xgBTy",
"solana/spl/5MAYDfq5yxtudAhtfyuMBuHZjgAbaS9tbEyEQYAhDS5y",
"solana/spl/5oVNBeEEQvYi1cX3ir8Dx5n1P7pdxydbGF2X4TxVusJm",
"solana/spl/5tB5D6DGJMxxHYmNkfJNG237x6pZGEwTzGpUUh62yQJ7",
"solana/spl/6cVgJUqo4nmvQpbgrDZwyfd6RwWw5bfnCamS3M9N1fd",
"solana/spl/6DNSN2BJsaPFdFFc1zP37kkeNe4Usc1Sqkzr9C9vPWcU",
"solana/spl/6LX8BhMQ4Sy2otmAWj7Y5sKd9YTVVUgfMsBzT6B9W7ct",
"solana/spl/6VNKqgz9hk7zRShTFdg5AnkfKwZUcojzwAkzxSH3bnUm",
"solana/spl/7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj",
"solana/spl/7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx",
"solana/spl/7kbnvuGBxxj8AG9qp8Scn56muWGaRaFqxg1FsRp3PaFT",
"solana/spl/7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn",
"solana/spl/7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
"solana/spl/9ET2QCQJdFkeKkuaampNbmicbA8eLYauFCWch9Ddh9p5",
"solana/spl/9mWRABuz2x6koTPCWiCPM49WUbcrNqGTHBV9T9k7y1o7",
"solana/spl/9nEqaUcb16sQ3Tn1psbkWqyhPdLmfHWjKGymREjsAgTE",
"solana/spl/a11bdAAuV8iB2fu7X6AxAvDTo1QZ8FXB3kk5eecdasp",
"solana/spl/A94X2fRy3wydNShU4dRaDyap2UuoeWJGWyATtyp61WZf",
"solana/spl/AFbX8oGjGpmVFywbVouvhQSRmiW2aR1mohfahi4Y2AdB",
"solana/spl/ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx",
"solana/spl/AURYydfxJib1ZkTir1Jn1J9ECYUtjb6rKQVmtYaixWPP",
"solana/spl/AZsHEMXd36Bj1EMNXhowJajpUXzrKcK57wW4ZGXVa7yR",
"solana/spl/BgwQjVNMWvt2d8CN51CsbniwRWyZ9H9HfHkEsvikeVuZ",
"solana/spl/BiDB55p4G3n1fGhwKFpxsokBMqgctL4qnZpDH1bVQxMD",
"solana/spl/BKipkearSqAUdNKa1WDstvcMjoPsSKBuNyvKDQDDu9WE",
"solana/spl/BLT1noyNr3GttckEVrtcfC6oyK6yV1DpPgSyXbncMwef",
"solana/spl/bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1",
"solana/spl/C98A4nkJXhpVZNAZdHUA95RpTF3T4whtQubL3YobiUX9",
"solana/spl/ChVzxWRmrTeSgwd3Ui3UumcN8KX7VK3WaD4KGeSKpypj",
"solana/spl/CKaKtYvz6dKPyMvYq9Rh3UBrnNqYZAyd7iF4hJtjUvks",
"solana/spl/CRWNYkqdgvhGGae9CKfNka58j6QQkaD5bLhKXvUYqnc1",
"solana/spl/CWBzupvyXN1Cf5rsBEHbzfTFvreLfUaJ77BMNLVJ739y",
"solana/spl/DAtU322C23YpoZyWBm8szk12QyqHa9rUQe1EYXzbm1JE",
"solana/spl/DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
"solana/spl/DFL1zNkaGPWm1BqAVqRjCZvHmwTFrEaJtbzJWgseoNJh",
"solana/spl/DkNihsQs1hqEwf9TgKP8FmGv7dmMQ7hnKjS2ZSmMZZBE",
"solana/spl/DUSTawucrTsGU8hcqRdHDCbuYhCPADMLM2VcCb8VnFnQ",
"solana/spl/E5rk3nmgLUuKUiS94gg4bpWwWwyjCMtddsAXkTFLtHEy",
"solana/spl/Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS",
"solana/spl/EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp",
"solana/spl/EcQCUYv57C4V6RoPxkVUiDwtX1SP8y8FP5AEToYL8Az",
"solana/spl/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"solana/spl/Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"solana/spl/ETAtLmCmsoiEEKfNrHKJ2kYy3MoABhU6NQvpSfij5tDs",
"solana/spl/F3nefJBcejYbtdREjui1T9DPh5dBgpkKq7u2GAAMXs5B",
"solana/spl/Fm9rHUTF5v3hwMLbStjZXqNBBoZyGriQaFM6sTFz3K8A",
"solana/spl/FR87nWEUxVgerFGhZM8Y4AggKGLnaXswr1Pd8wZ4kZcp",
"solana/spl/GDfnEsia2WLAW5t8yx2X5j2mkfA74i5kwGdDuZHt7XmG",
"solana/spl/GDsVXtyt2CBwieKSYMEsjjZXXvqz2G2VwudD7EvXzoEU",
"solana/spl/GENEtH5amGSi8kHAtQoezp1XEXwZJ8vcuePYnXdKrMYz",
"solana/spl/GFX1ZjR2P15tmrSwow6FjyDYcEkoFb4p4gJCpLBjaxHD",
"solana/spl/GsNzxJfFn6zQdJGeYsupJWzUAm57Ba7335mfhWvFiE9Z",
"solana/spl/HBB111SCo9jkCejsZfz8Ec8nH7T6THF8KEKSnvwT6XK6",
"solana/spl/HHjoYwUp5aU6pnrvN4s2pwEErwXNZKhxKGYjRJMoBjLw",
"solana/spl/HhJpBhRRn4g56VsyLuT8DL5Bv31HkXqsrahTTUCZeZg4",
"solana/spl/hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux",
"solana/spl/HxhWkVpk5NS4Ltg5nij2G671CKXFRKPK8vy271Ub4uEK",
"solana/spl/HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3",
"solana/spl/J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
"solana/spl/jtojtomepa8beP8AuQc6eXt5FriJwfFMwQx2v2f9mCL",
"solana/spl/kinXdEcpDQeHPEuQnqmUgtYykqKGVFq6CeVX5iAHJq6",
"solana/spl/MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac",
"solana/spl/MAPS41MDahZ9QdKXhVa4dWB9RuyfV4XqhyAZ8XcYepb",
"solana/spl/MEANeD3XDdUmNMsRGjASkSWdC8prLYsoRJ61pPeHctD",
"solana/spl/METAewgxyPbgwsseH8T16a39CQ5VyVxZi9zXiDPY18m",
"solana/spl/MNDEFzGvMt87ueuHvVU9VcTqsAP5b3fTGPsHuuPA5ey",
"solana/spl/mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
"solana/spl/NFTUkR4u7wKxy9QLaX2TGvd9oZSWoMo4jqSJqdMb7Nk",
"solana/spl/orcaEKTdK7LKz57vaAYr9QeNsVEPfiu6QeMU1kektZE",
"solana/spl/poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk",
"solana/spl/PoRTjZMPXb9T7dyU7tpLEZRQj7e6ssfAE62j2oQuc6y",
"solana/spl/PRSMNsEPqhGVCH1TtWiJqPjJyh2cKrLostPZTNy1o5x",
"solana/spl/PsyFiqqjiv41G7o5SMRzDJCu4psptThNR2GtfeGHfSq",
"solana/spl/RLBxxFkseAZ4RgJH3Sqn8jXxhmGoz9jWxDNJMh8pL7a",
"solana/spl/rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof",
"solana/spl/Saber2gLauYim4Mvftnrasomsv6NvAuncvMEZwcLpD1",
"solana/spl/SCSuPPNUSypLBsV4darsrYNg4ANPgaGhKhsA3GmMyjz",
"solana/spl/SLCLww7nc1PD2gQPQdGayHviVVcpMthnqUz2iWKhNQV",
"solana/spl/SLNDpmoWTVADgEdndyvWzroNL7zSi1dF9PC3xHGtPwp",
"solana/spl/So11111111111111111111111111111111111111112",
"solana/spl/SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt",
"solana/spl/StepAscQoEioFxxWGnh2sLBDFp9d8rvKz2Yp39iDpyT",
"solana/spl/Taki7fi3Zicv7Du1xNAWLaf6mRK7ikdn77HeGzgwvo4",
"solana/spl/TuLipcqtGVXP9XR62wM8WWCm6a9vhLs7T1uoWBk6FDs",
"solana/spl/UXPhBoR3qG4UCiGNJfV7MqhHyFqKN68g45GoYvAeL2M",
"solana/spl/xxxxa1sKNGwFtw2kFn8XauW9xq8hBZ5kVtcSesTT9fW",
"solana/spl/z3dn17yLaGMKffVogeFHQ9zWVcXgqgf3PQnDsNs2g6M",
"solana/spl/zebeczgi5fSEtbpfQKVZKCJ3WgYXxjkMUkNNx7fLKAF",
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exports[`solana currency bridge scanAccounts solana seed 1 1`] = `
"pendingOperations": [],
"spendableBalance": "7960720",
"starred": false,
"state": "initialized",
"swapHistory": [],
"tokenId": "solana/spl/So11111111111111111111111111111111111111112",
"type": "TokenAccountRaw",
Expand Down
4 changes: 4 additions & 0 deletions libs/ledger-live-common/src/families/solana/bridge/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
assignToAccountRaw,
fromOperationExtraRaw,
toOperationExtraRaw,
assignFromTokenAccountRaw,
assignToTokenAccountRaw,
} from "../serialization";
import type { SolanaAccount, SolanaPreloadDataV1, Transaction } from "../types";
import { endpointByCurrencyId } from "../utils";
Expand Down Expand Up @@ -171,6 +173,8 @@ export function makeBridges({
assignToAccountRaw,
toOperationExtraRaw,
fromOperationExtraRaw,
assignFromTokenAccountRaw,
assignToTokenAccountRaw,
};

const currencyBridge: CurrencyBridge = {
Expand Down
31 changes: 30 additions & 1 deletion libs/ledger-live-common/src/families/solana/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import {
SolanaOperationExtraRaw,
SolanaResources,
SolanaResourcesRaw,
SolanaTokenAccount,
SolanaTokenAccountRaw,
} from "./types";
import { Account, AccountRaw, OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
import {
Account,
AccountRaw,
OperationExtra,
OperationExtraRaw,
TokenAccount,
TokenAccountRaw,
} from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";

export function toSolanaResourcesRaw(resources: SolanaResources): SolanaResourcesRaw {
Expand Down Expand Up @@ -79,3 +88,23 @@ export function toOperationExtraRaw(extra: OperationExtra): OperationExtraRaw {
function isExtraValid(extra: OperationExtra | OperationExtraRaw): boolean {
return !!extra && typeof extra === "object";
}

export function assignToTokenAccountRaw(
tokenAccount: TokenAccount,
tokenAccountRaw: TokenAccountRaw,
) {
const solanaTokenAccount = tokenAccount as SolanaTokenAccount;
if (solanaTokenAccount.state) {
(tokenAccountRaw as SolanaTokenAccountRaw).state = solanaTokenAccount.state;
}
}

export function assignFromTokenAccountRaw(
tokenAccountRaw: TokenAccountRaw,
tokenAccount: TokenAccount,
) {
const stateRaw = (tokenAccountRaw as SolanaTokenAccountRaw).state;
if (stateRaw) {
(tokenAccount as SolanaTokenAccount).state = stateRaw;
}
}
32 changes: 30 additions & 2 deletions libs/ledgerjs/packages/types-live/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ Ledger Live main types.
* [Parameters](#parameters)
* [assignFromAccountRaw](#assignfromaccountraw)
* [Parameters](#parameters-1)
* [initAccount](#initaccount)
* [assignToTokenAccountRaw](#assigntotokenaccountraw)
* [Parameters](#parameters-2)
* [assignFromTokenAccountRaw](#assignfromtokenaccountraw)
* [Parameters](#parameters-3)
* [initAccount](#initaccount)
* [Parameters](#parameters-4)
* [CurrenciesData](#currenciesdata)
* [Properties](#properties-11)
* [DatasetTest](#datasettest)
Expand Down Expand Up @@ -483,6 +487,30 @@ Type: function (accountRaw: [AccountRaw](#accountraw), account: [Account](#accou
* `accountRaw` **[AccountRaw](#accountraw)** The account in its serialized form.
* `account` **[Account](#account)** The original account object.

#### assignToTokenAccountRaw

This function mutates the 'tokenAccountRaw' object in-place to add any extra fields that the coin may need to set.
It is called during the serialization mechanism

Type: function (tokenAccount: [TokenAccount](#tokenaccount), tokenAccountRaw: [TokenAccountRaw](#tokenaccountraw)): void

##### Parameters

* `tokenAccount` **[TokenAccount](#tokenaccount)** The original token account object.
* `tokenAccountRaw` **[TokenAccountRaw](#tokenaccountraw)** The token account in its serialized form.

#### assignFromTokenAccountRaw

This function mutates the 'tokenAccount' object in-place to add any extra fields that the coin may need to set.
It is called during the deserialization mechanism

Type: function (tokenAccountRaw: [TokenAccountRaw](#tokenaccountraw), tokenAccount: [TokenAccount](#tokenaccount)): void

##### Parameters

* `tokenAccountRaw` **[TokenAccountRaw](#tokenaccountraw)** The token account in its serialized form.
* `tokenAccount` **[TokenAccount](#tokenaccount)** The original token account object.

#### initAccount

This function mutates the 'account' object to extend it with any extra fields of the coin.
Expand Down Expand Up @@ -1007,7 +1035,7 @@ Type: {ticker: [string](https://developer.mozilla.org/docs/Web/JavaScript/Refere

### OperationType

Type: (`"IN"` | `"OUT"` | `"NONE"` | `"CREATE"` | `"REVEAL"` | `"DELEGATE"` | `"UNDELEGATE"` | `"REDELEGATE"` | `"REWARD"` | `"FEES"` | `"FREEZE"` | `"UNFREEZE"` | `"WITHDRAW_EXPIRE_UNFREEZE"` | `"UNDELEGATE_RESOURCE"` | `"LEGACY_UNFREEZE"` | `"VOTE"` | `"REWARD_PAYOUT"` | `"BOND"` | `"UNBOND"` | `"WITHDRAW_UNBONDED"` | `"SET_CONTROLLER"` | `"SLASH"` | `"NOMINATE"` | `"CHILL"` | `"APPROVE"` | `"OPT_IN"` | `"OPT_OUT"` | `"LOCK"` | `"UNLOCK"` | `"WITHDRAW"` | `"REVOKE"` | `"ACTIVATE"` | `"REGISTER"` | `"NFT_IN"` | `"NFT_OUT"` | `"STAKE"` | `"UNSTAKE"` | `"WITHDRAW_UNSTAKED"`)
Type: (`"IN"` | `"OUT"` | `"NONE"` | `"CREATE"` | `"REVEAL"` | `"DELEGATE"` | `"UNDELEGATE"` | `"REDELEGATE"` | `"REWARD"` | `"FEES"` | `"FREEZE"` | `"UNFREEZE"` | `"WITHDRAW_EXPIRE_UNFREEZE"` | `"UNDELEGATE_RESOURCE"` | `"LEGACY_UNFREEZE"` | `"VOTE"` | `"REWARD_PAYOUT"` | `"BOND"` | `"UNBOND"` | `"WITHDRAW_UNBONDED"` | `"SET_CONTROLLER"` | `"SLASH"` | `"NOMINATE"` | `"CHILL"` | `"APPROVE"` | `"OPT_IN"` | `"OPT_OUT"` | `"LOCK"` | `"UNLOCK"` | `"WITHDRAW"` | `"REVOKE"` | `"ACTIVATE"` | `"REGISTER"` | `"NFT_IN"` | `"NFT_OUT"` | `"STAKE"` | `"UNSTAKE"` | `"WITHDRAW_UNSTAKED"` | `"BURN"`)

### Operation

Expand Down
21 changes: 20 additions & 1 deletion libs/ledgerjs/packages/types-live/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { BigNumber } from "bignumber.js";
import type { Observable } from "rxjs";
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
import type { AccountLike, Account, AccountRaw } from "./account";
import type { AccountLike, Account, AccountRaw, TokenAccount, TokenAccountRaw } from "./account";
import type {
SignOperationEvent,
SignedOperation,
Expand Down Expand Up @@ -182,6 +182,25 @@ export interface AccountBridge<T extends TransactionCommon> {
* @param {Account} account - The original account object.
*/
assignFromAccountRaw?: (accountRaw: AccountRaw, account: Account) => void;
/**
* This function mutates the 'tokenAccountRaw' object in-place to add any extra fields that the coin may need to set.
* It is called during the serialization mechanism
*
* @param {TokenAccount} tokenAccount - The original token account object.
* @param {TokenAccountRaw} tokenAccountRaw - The token account in its serialized form.
*/
assignToTokenAccountRaw?: (tokenAccount: TokenAccount, tokenAccountRaw: TokenAccountRaw) => void;
/**
* This function mutates the 'tokenAccount' object in-place to add any extra fields that the coin may need to set.
* It is called during the deserialization mechanism
*
* @param {TokenAccountRaw} tokenAccountRaw - The token account in its serialized form.
* @param {TokenAccount} tokenAccount - The original token account object.
*/
assignFromTokenAccountRaw?: (
tokenAccountRaw: TokenAccountRaw,
tokenAccount: TokenAccount,
) => void;
/**
* This function mutates the 'account' object to extend it with any extra fields of the coin.
* For instance bitcoinResources needs to be created.
Expand Down

0 comments on commit 835b980

Please sign in to comment.