Skip to content

Commit

Permalink
Add support for operation responses coming in Protocol 20. (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Aug 21, 2023
1 parent 0c99413 commit fc9ba11
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 4 deletions.
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
46 changes: 46 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,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<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

0 comments on commit fc9ba11

Please sign in to comment.