From fc9ba11f75e5b2ac613ff4b9eee4748883510ac6 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 21 Aug 2023 14:26:32 -0700 Subject: [PATCH] Add support for operation responses coming in Protocol 20. (#845) --- CHANGELOG.md | 32 ++++++++++++++++++++++--- src/horizon_api.ts | 46 ++++++++++++++++++++++++++++++++++++ src/server_api.ts | 58 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b4136679..27b519e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,35 @@ A breaking change will get clearly marked in this log. ### Add -- Asset stat records (`ServerApi.AssetRecord`) contain two new fields to support the Protocol 20 (Soroban) release ([#TODO](https://github.com/stellar/js-stellar-sdk/pulls/)): - * `num_contracts` - the integer quantity of contracts that hold this asset - * `contracts_amount` - the total units of that asset held by contracts +- Asset stat records (`ServerApi.AssetRecord`) contain two new fields to support the Protocol 20 (Soroban) release ([#841](https://github.com/stellar/js-stellar-sdk/pull/841)): + * `num_contracts` - the integer quantity of contracts that hold this asset + * `contracts_amount` - the total units of that asset held by contracts +- New operation responses ([#845](https://github.com/stellar/js-stellar-sdk/pull/845)): + * `invokeHostFunction`: see `Horizon.InvokeHostFunctionOperationResponse` + * `bumpFootprintExpiration`: see `Horizon.BumpFootprintExpirationOperationResponse` + * `restoreFootprint`: see `Horizon.RestoreFootprintOperationResponse` + * You can refer to the actual definitions for details, but the gist of the schemas is below: +```ts +interface InvokeHostFunctionOperationResponse { + function: string; + parameters: { + value: string; + type: string; + }[]; + address: string; + salt: string; + asset_balance_changes: { + type: string; + from: string; + to: string; + amount: string; + }[]; +} +interface BumpFootprintExpirationOperationResponse { + ledgersToExpire: string; +} +interface RestoreFootprintOperationResponse {}; +``` ## [v11.0.0-beta.1](https://github.com/stellar/js-stellar-sdk/compare/v11.0.0-beta.0...v11.0.0-beta.1) diff --git a/src/horizon_api.ts b/src/horizon_api.ts index 7b206905a..cb4116195 100644 --- a/src/horizon_api.ts +++ b/src/horizon_api.ts @@ -218,6 +218,9 @@ export namespace Horizon { setTrustLineFlags = "set_trust_line_flags", liquidityPoolDeposit = "liquidity_pool_deposit", liquidityPoolWithdraw = "liquidity_pool_withdraw", + invokeHostFunction = "invoke_host_function", + bumpFootprintExpiration = "bump_footprint_expiration", + restoreFootprint = "restore_footprint", } export enum OperationResponseTypeI { createAccount = 0, @@ -244,6 +247,9 @@ export namespace Horizon { setTrustLineFlags = 21, liquidityPoolDeposit = 22, liquidityPoolWithdraw = 23, + invokeHostFunction = 24, + bumpFootprintExpiration = 25, + restoreFootprint = 26, } export interface BaseOperationResponse< T extends OperationResponseType = OperationResponseType, @@ -563,6 +569,46 @@ export namespace Horizon { reserves_received: Reserve[]; } + export interface BalanceChange { + asset_type: string; + asset_code?: string; + asset_issuer?: string; + + type: string; + from: string; + to: string; + amount: string; + } + + export interface InvokeHostFunctionOperationResponse + extends BaseOperationResponse< + OperationResponseType.invokeHostFunction, + OperationResponseTypeI.invokeHostFunction + > { + function: string; + parameters: { + value: string; + type: string; + }[]; + address: string; + salt: string; + asset_balance_changes: BalanceChange[]; + } + + export interface BumpFootprintExpirationOperationResponse + extends BaseOperationResponse< + OperationResponseType.bumpFootprintExpiration, + OperationResponseTypeI.bumpFootprintExpiration + > { + ledgers_to_expire: number; + } + + export interface RestoreFootprintOperationResponse + extends BaseOperationResponse< + OperationResponseType.restoreFootprint, + OperationResponseTypeI.restoreFootprint + > {}; + export interface ResponseCollection { _links: { self: ResponseLink; diff --git a/src/server_api.ts b/src/server_api.ts index bb210b09d..5c3d4f2a2 100644 --- a/src/server_api.ts +++ b/src/server_api.ts @@ -304,6 +304,54 @@ export namespace ServerApi { OperationResponseTypeI.revokeSponsorship >, Horizon.RevokeSponsorshipOperationResponse {} + export interface ClawbackOperationRecord + extends BaseOperationRecord< + OperationResponseType.clawback, + OperationResponseTypeI.clawback + >, + Horizon.ClawbackOperationResponse {} + export interface ClawbackClaimableBalanceOperationRecord + extends BaseOperationRecord< + OperationResponseType.clawbackClaimableBalance, + OperationResponseTypeI.clawbackClaimableBalance + >, + Horizon.ClawbackClaimableBalanceOperationResponse {} + export interface SetTrustLineFlagsOperationRecord + extends BaseOperationRecord< + OperationResponseType.setTrustLineFlags, + OperationResponseTypeI.setTrustLineFlags + >, + Horizon.SetTrustLineFlagsOperationResponse {} + export interface DepositLiquidityOperationRecord + extends BaseOperationRecord< + OperationResponseType.liquidityPoolDeposit, + OperationResponseTypeI.liquidityPoolDeposit + >, + Horizon.DepositLiquidityOperationResponse {} + export interface WithdrawLiquidityOperationRecord + extends BaseOperationRecord< + OperationResponseType.liquidityPoolWithdraw, + OperationResponseTypeI.liquidityPoolWithdraw + >, + Horizon.WithdrawLiquidityOperationResponse {} + export interface InvokeHostFunctionOperationRecord + extends BaseOperationRecord< + OperationResponseType.invokeHostFunction, + OperationResponseTypeI.invokeHostFunction + >, + Horizon.InvokeHostFunctionOperationResponse {} + export interface BumpFootprintExpirationOperationRecord + extends BaseOperationRecord< + OperationResponseType.bumpFootprintExpiration, + OperationResponseTypeI.bumpFootprintExpiration + >, + Horizon.BumpFootprintExpirationOperationResponse {} + export interface RestoreFootprintOperationRecord + extends BaseOperationRecord< + OperationResponseType.restoreFootprint, + OperationResponseTypeI.restoreFootprint + >, + Horizon.RestoreFootprintOperationResponse {} export type OperationRecord = | CreateAccountOperationRecord @@ -323,7 +371,15 @@ export namespace ServerApi { | ClaimClaimableBalanceOperationRecord | BeginSponsoringFutureReservesOperationRecord | EndSponsoringFutureReservesOperationRecord - | RevokeSponsorshipOperationRecord; + | RevokeSponsorshipOperationRecord + | ClawbackClaimableBalanceOperationRecord + | ClawbackOperationRecord + | SetTrustLineFlagsOperationRecord + | DepositLiquidityOperationRecord + | WithdrawLiquidityOperationRecord + | InvokeHostFunctionOperationRecord + | BumpFootprintExpirationOperationRecord + | RestoreFootprintOperationRecord; export namespace TradeRecord { interface Base extends Horizon.BaseResponse {