-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adapt code organization for alpaca calls Signed-off-by: Stéphane Prohaszka <[email protected]> * feat: add getBalance Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: missing export Signed-off-by: Stéphane Prohaszka <[email protected]> * feat(xlm): add listOperations Signed-off-by: Stéphane Prohaszka <[email protected]> * feat: add craftTransaction Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: remove generics as it will forbid the use of generic Api creation Signed-off-by: Stéphane Prohaszka <[email protected]> * feat(xlm): add lastBlock function Signed-off-by: Stéphane Prohaszka <[email protected]> * feat(xlm): add combine function Signed-off-by: Stéphane Prohaszka <[email protected]> * feat(xlm): add estimation fees Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: missing export Signed-off-by: Stéphane Prohaszka <[email protected]> * fix(xlm): config typo Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: activate useAllAmount Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: changeset Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: update test Signed-off-by: Stéphane Prohaszka <[email protected]> * fix: rebase issue Signed-off-by: Stéphane Prohaszka <[email protected]> * chore: update bot device to NanoSP Signed-off-by: Stéphane Prohaszka <[email protected]> --------- Signed-off-by: Stéphane Prohaszka <[email protected]>
- Loading branch information
1 parent
2dd4825
commit 9c2f1b3
Showing
58 changed files
with
965 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@ledgerhq/coin-stellar": minor | ||
"@ledgerhq/live-common": minor | ||
"@ledgerhq/coin-framework": minor | ||
"@ledgerhq/coin-polkadot": patch | ||
"@ledgerhq/coin-tezos": patch | ||
"@ledgerhq/coin-xrp": patch | ||
--- | ||
|
||
Prepare CoinModule Stellar for Alpaca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
libs/coin-modules/coin-stellar/src/api/index.integ.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { Api } from "@ledgerhq/coin-framework/api/index"; | ||
import { createApi } from "."; | ||
|
||
describe("Stellar Api", () => { | ||
let module: Api; | ||
const address = "GD6QELUZPSKPRWVXOQ3F6GBF4OBRMCHO5PHREXH4ZRTPJAG7V5MD7JGX"; | ||
|
||
beforeAll(() => { | ||
module = createApi({ | ||
explorer: { | ||
url: "https://horizon-testnet.stellar.org/", | ||
}, | ||
}); | ||
}); | ||
|
||
describe("estimateFees", () => { | ||
it("returns a default value", async () => { | ||
// Given | ||
const amount = BigInt(100_000); | ||
|
||
// When | ||
const result = await module.estimateFees(address, amount); | ||
|
||
// Then | ||
expect(result).toEqual(BigInt(100)); | ||
}); | ||
}); | ||
|
||
describe("listOperations", () => { | ||
it("returns a list regarding address parameter", async () => { | ||
// When | ||
const result = await module.listOperations(address, 0); | ||
|
||
// Then | ||
expect(result.length).toBeGreaterThanOrEqual(1); | ||
result.forEach(operation => { | ||
expect(operation.address).toEqual(address); | ||
const isSenderOrReceipt = | ||
operation.senders.includes(address) || operation.recipients.includes(address); | ||
expect(isSenderOrReceipt).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("lastBlock", () => { | ||
it("returns last block info", async () => { | ||
// When | ||
const result = await module.lastBlock(); | ||
|
||
// Then | ||
expect(result.hash).toBeDefined(); | ||
expect(result.height).toBeDefined(); | ||
expect(result.time).toBeInstanceOf(Date); | ||
}); | ||
}); | ||
|
||
describe("getBalance", () => { | ||
it("returns a list regarding address parameter", async () => { | ||
// When | ||
const result = await module.getBalance(address); | ||
|
||
// Then | ||
expect(result).toBeGreaterThan(0); | ||
}); | ||
}); | ||
|
||
describe("craftTransaction", () => { | ||
it("returns a raw transaction", async () => { | ||
// When | ||
const result = await module.craftTransaction(address, { | ||
mode: "send", | ||
recipient: "GD6QELUZPSKPRWVXOQ3F6GBF4OBRMCHO5PHREXH4ZRTPJAG7V5MD7JGX", | ||
amount: BigInt(1_000_000), | ||
fee: BigInt(100), | ||
}); | ||
|
||
// Then | ||
expect(result.slice(0, 67)).toEqual( | ||
"AAAAAgAAAAD9Ai6ZfJT42rd0Nl8YJeODFgju688SXPzMZvSA369YPwAAAGQAAHloAAA", | ||
); | ||
expect(result.slice(70)).toEqual( | ||
"AAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAD9Ai6ZfJT42rd0Nl8YJeODFgju688SXPzMZvSA369YPwAAAAAAAAAAAA9CQAAAAAAAAAAA", | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Api } from "@ledgerhq/coin-framework/api/index"; | ||
import coinConfig, { type StellarConfig } from "../config"; | ||
import { | ||
broadcast, | ||
combine, | ||
craftTransaction, | ||
estimateFees, | ||
getBalance, | ||
listOperations, | ||
lastBlock, | ||
} from "../logic"; | ||
|
||
export function createApi(config: StellarConfig): Api { | ||
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } })); | ||
|
||
return { | ||
broadcast, | ||
combine: compose, | ||
craftTransaction: craft, | ||
estimateFees, | ||
getBalance, | ||
lastBlock, | ||
listOperations, | ||
}; | ||
} | ||
|
||
type Supplement = { | ||
assetCode?: string | undefined; | ||
assetIssuer?: string | undefined; | ||
memoType?: string | null | undefined; | ||
memoValue?: string | null | undefined; | ||
}; | ||
function isSupplement(supplement: unknown): supplement is Supplement { | ||
return typeof supplement === "object"; | ||
} | ||
async function craft( | ||
address: string, | ||
transaction: { | ||
mode: string; | ||
recipient: string; | ||
amount: bigint; | ||
fee: bigint; | ||
supplement?: unknown; | ||
}, | ||
): Promise<string> { | ||
const supplement = isSupplement(transaction.supplement) | ||
? { | ||
assetCode: transaction.supplement?.assetCode, | ||
assetIssuer: transaction.supplement?.assetIssuer, | ||
memoType: transaction.supplement?.memoType, | ||
memoValue: transaction.supplement?.memoValue, | ||
} | ||
: {}; | ||
const tx = await craftTransaction( | ||
{ address }, | ||
{ | ||
...transaction, | ||
assetCode: supplement?.assetCode, | ||
assetIssuer: supplement?.assetIssuer, | ||
memoType: supplement?.memoType, | ||
memoValue: supplement?.memoValue, | ||
}, | ||
); | ||
return tx.xdr; | ||
} | ||
|
||
function compose(tx: string, signature: string, pubkey?: string): string { | ||
if (!pubkey) { | ||
throw new Error("Missing pubkey"); | ||
} | ||
return combine(tx, signature, pubkey); | ||
} |
Oops, something went wrong.