Skip to content
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

Add support for operation responses coming in Protocol 20. #845

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions src/horizon_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -563,6 +569,42 @@ export namespace Horizon {
reserves_received: Reserve[];
}

export interface BalanceChange {
type: string;
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
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
> {
ledgersToExpire: string;
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
}

export interface RestoreFootprintOperationResponse
extends BaseOperationResponse<
OperationResponseType.restoreFootprint,
OperationResponseTypeI.restoreFootprint
> {};

export interface ResponseCollection<T extends BaseResponse = BaseResponse> {
_links: {
self: ResponseLink;
Expand Down
58 changes: 57 additions & 1 deletion src/server_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down