Skip to content

Commit

Permalink
Rename to be specific to built-in tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Sep 16, 2024
1 parent bb7771b commit 8bc0e2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,13 @@ export class Server {
}

/**
* Returns a contract's balance of a particular token, if any.
* Returns a contract's balance of a particular SAC asset, if any.
*
* This is a convenience wrapper around {@link Server.getLedgerEntries}.
*
* @param {string} contractId the contract ID (string `C...`) whose
* balance of `token` you want to know
* @param {Asset} token the token/asset (e.g. `USDC:GABC...`) that
* balance of `sac` you want to know
* @param {Asset} sac the built-in SAC token (e.g. `USDC:GABC...`) that
* you are querying from the given `contract`.
* @param {string} [networkPassphrase] optionally, the network passphrase to
* which this token applies. If omitted, a request about network
Expand All @@ -924,10 +924,11 @@ export class Server {
* @throws {TypeError} If `contractId` is not a valid contract strkey (C...).
*
* @see getLedgerEntries
* @see https://developers.stellar.org/docs/tokens/stellar-asset-contract
*/
public async getContractBalance(
public async getSACBalance(
contractId: string,
token: Asset,
sac: Asset,
networkPassphrase?: string
): Promise<Api.ContractBalanceResponse> {
if (!StrKey.isValidContract(contractId)) {
Expand All @@ -938,8 +939,8 @@ export class Server {
const passphrase: string = networkPassphrase
?? await this.getNetwork().then(n => n.passphrase);

// Turn token into predictable contract ID
const tokenId = token.contractId(passphrase);
// Turn SAC into predictable contract ID
const sacId = sac.contractId(passphrase);

// Rust union enum type with "Balance(ScAddress)" structure
const key = xdr.ScVal.scvVec([
Expand All @@ -954,7 +955,7 @@ export class Server {
// of N XLM).
const ledgerKey = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: new Address(tokenId).toScAddress(),
contract: new Address(sacId).toScAddress(),
durability: xdr.ContractDataDurability.persistent(),
key
})
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server/soroban/get_contract_balance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("Server#getContractBalance", function () {
buildMockResult(this);

this.server
.getContractBalance(contract, token, StellarSdk.Networks.TESTNET)
.getSACBalance(contract, token, StellarSdk.Networks.TESTNET)
.then((response) => {
expect(response.latestLedger).to.equal(1000);
expect(response.balanceEntry).to.not.be.undefined;
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("Server#getContractBalance", function () {
);

this.server
.getContractBalance(contract, token)
.getSACBalance(contract, token)
.then((response) => {
expect(response.latestLedger).to.equal(1000);
expect(response.balanceEntry).to.not.be.undefined;
Expand Down

0 comments on commit 8bc0e2d

Please sign in to comment.