Skip to content

Commit

Permalink
Issue stellar#299: Types peovided for effects, with Go Package being …
Browse files Browse the repository at this point in the history
…the reference, in addition to moving Asset and Offer Types to their own files.
  • Loading branch information
RabeaWahab committed Apr 21, 2021
1 parent 563ab74 commit 1b3c7fb
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 144 deletions.
243 changes: 99 additions & 144 deletions src/server_api.ts
@@ -1,9 +1,58 @@
import { Asset, AssetType } from "stellar-base";
import { Asset } from "stellar-base";
import { Omit } from "utility-types";
import { Horizon } from "./horizon_api";

// more types
import { AccountRecordSigners as AccountRecordSignersType } from "./types/account";
import { AssetRecord as AssetRecordType } from "./types/assets";
import {
AccountCreated,
// Types of effects
AccountCredited,
AccountDebited,
AccountFlagsUpdated,
AccountHomeDomainUpdated,
AccountSponsporshipCreated,
AccountSponsporshipRemoved,
AccountSponsporshipUpdated,
AccountThresholdsUpdated,
BaseEffectRecord,
ClaimableBalanceClaimantCreated,
ClaimableBalanceClaimed,
ClaimableBalanceCreated,
ClaimableBalanceSponsorshipCreated,
ClaimableBalanceSponsorshipRemoved,
ClaimableBalanceSponsorshipUpdated,
DataCreated,
DataRemoved,
DataUpdated,
DateSponsporshipCreated,
DateSponsporshipRemoved,
DateSponsporshipUpdated,
SequenceBumped,
SignerCreated,
SignerRemoved,
SignerSponsorshipCreated,
SignerSponsorshipRemoved,
SignerSponsorshipUpdated,
SignerUpdated,
TrustlineAuthorized,
TrustlineAutorizedToMaintainLiabilities,
TrustlineCreated,
TrustlineDeautorized,
TrustlineRemoved,
TrustlineSponsporshipCreated,
TrustlineSponsporshipRemoved,
TrustlineSponsporshipUpdated,
TrustlineUpdated,
} from "./types/effects";
import { OfferRecord as OfferRecordType } from "./types/offer";

/* tslint:disable-next-line: no-namespace */
export namespace ServerApi {
export type OfferRecord = OfferRecordType;
export type AccountRecordSigners = AccountRecordSignersType;
export type AssetRecord = AssetRecordType;
export interface CollectionPage<
T extends Horizon.BaseResponse = Horizon.BaseResponse
> {
Expand All @@ -25,10 +74,54 @@ export namespace ServerApi {
T extends Horizon.BaseResponse = Horizon.BaseResponse
> = (options?: CallFunctionTemplateOptions) => Promise<CollectionPage<T>>;

export interface AccountRecordSigners {
key: string;
weight: number;
type: string;
type BaseEffectRecordFromTypes =
| AccountCreated
| AccountCredited
| AccountDebited
| AccountThresholdsUpdated
| AccountHomeDomainUpdated
| AccountFlagsUpdated
| DataCreated
| DataRemoved
| DataUpdated
| SequenceBumped
| SignerCreated
| SignerRemoved
| SignerUpdated
| TrustlineCreated
| TrustlineRemoved
| TrustlineUpdated
| TrustlineAuthorized
| TrustlineDeautorized
| TrustlineAutorizedToMaintainLiabilities
| ClaimableBalanceCreated
| ClaimableBalanceClaimed
| ClaimableBalanceClaimantCreated
| AccountSponsporshipCreated
| AccountSponsporshipRemoved
| AccountSponsporshipUpdated
| TrustlineSponsporshipCreated
| TrustlineSponsporshipUpdated
| TrustlineSponsporshipRemoved
| DateSponsporshipCreated
| DateSponsporshipUpdated
| DateSponsporshipRemoved
| ClaimableBalanceSponsorshipCreated
| ClaimableBalanceSponsorshipRemoved
| ClaimableBalanceSponsorshipUpdated
| SignerSponsorshipCreated
| SignerSponsorshipUpdated
| SignerSponsorshipRemoved;

export type EffectRecord = BaseEffectRecordFromTypes & EffectRecordMethods;
export interface ClaimableBalanceRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
asset: string;
amount: string;
sponsor?: string;
last_modified_ledger: number;
claimants: Horizon.Claimant[];
}
export interface AccountRecord extends Horizon.BaseResponse {
id: string;
Expand Down Expand Up @@ -56,110 +149,11 @@ export namespace ServerApi {
payments: CallCollectionFunction<PaymentOperationRecord>;
trades: CallCollectionFunction<TradeRecord>;
}

export interface ClaimableBalanceRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
asset: string;
amount: string;
sponsor?: string;
last_modified_ledger: number;
claimants: Horizon.Claimant[];
}

export interface EffectRecord extends Horizon.BaseResponse {
account: string;
paging_token: string;
type_i: string;
type: string;
created_at: string;
id: string;

// account_debited / credited / trustline_created
amount?: any;
asset_type?: string;
asset_code?: string;
asset_issuer?: string;

// trustline_created / removed
limit?: string;

// signer_created
public_key?: string;

// trade
offer_id?: number | string;
bought_amount?: string;
bought_asset_type?: string;
bought_asset_code?: string;
bought_asset_issuer?: string;
sold_amount?: string;
sold_asset_type?: string;
sold_asset_code?: string;
sold_asset_issuer?: string;

// account_created
starting_balance?: string;

// These were retrieved from the go repo, not through direct observation
// so they could be wrong!

// account thresholds updated
low_threshold?: number;
med_threshold?: number;
high_threshold?: number;

// home domain updated
home_domain?: string;

// account flags updated
auth_required_flag?: boolean;
auth_revokable_flag?: boolean;

// seq bumped
new_seq?: number | string;

// signer created / removed / updated
weight?: number;
key?: string;

// trustline authorized / deauthorized
trustor?: string;

// claimable_balance_created
// claimable_balance_claimant_created
// claimable_balance_claimed
balance_id?: string;
asset?: string;
predicate?: Horizon.Predicate;

// account_sponsorship_created
// trustline_sponsorship_created
// claimable_balance_sponsorship_created
// signer_sponsorship_created
// data_sponsorship_created
sponsor?: string;
signer?: string;
data_name?: string;

// account_sponsorship_updated
// account_sponsorship_removed
// trustline_sponsorship_updated
// trustline_sponsorship_removed
// claimable_balance_sponsorship_updated
// claimable_balance_sponsorship_removed
// signer_sponsorship_updated
// signer_sponsorship_removed
// data_sponsorship_updated
// data_sponsorship_removed
new_sponsor?: string;
former_sponsor?: string;

interface EffectRecordMethods {
operation?: CallFunction<OperationRecord>;
precedes?: CallFunction<EffectRecord>;
succeeds?: CallFunction<EffectRecord>;
}

export interface LedgerRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
Expand All @@ -186,26 +180,6 @@ export namespace ServerApi {
transactions: CallCollectionFunction<TransactionRecord>;
}

export interface OfferAsset {
asset_type: AssetType;
asset_code?: string;
asset_issuer?: string;
}

export interface OfferRecord extends Horizon.BaseResponse {
id: number | string;
paging_token: string;
seller: string;
selling: OfferAsset;
buying: OfferAsset;
amount: string;
price_r: Horizon.PriceRShorthand;
price: string;
last_modified_ledger: number;
last_modified_time: string;
sponsor?: string;
}

import OperationResponseType = Horizon.OperationResponseType;
import OperationResponseTypeI = Horizon.OperationResponseTypeI;
export interface BaseOperationRecord<
Expand All @@ -218,7 +192,6 @@ export namespace ServerApi {
effects: CallCollectionFunction<EffectRecord>;
transaction: CallFunction<TransactionRecord>;
}

export interface CreateAccountOperationRecord
extends BaseOperationRecord<
OperationResponseType.createAccount,
Expand Down Expand Up @@ -350,7 +323,6 @@ export namespace ServerApi {
| BeginSponsoringFutureReservesOperationRecord
| EndSponsoringFutureReservesOperationRecord
| RevokeSponsorshipOperationRecord;

export interface TradeRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
Expand All @@ -374,7 +346,6 @@ export namespace ServerApi {
counter: CallFunction<AccountRecord>;
operation: CallFunction<OperationRecord>;
}

export interface TransactionRecord
extends Omit<Horizon.TransactionResponse, "ledger"> {
ledger_attr: Horizon.TransactionResponse["ledger"];
Expand All @@ -387,21 +358,6 @@ export namespace ServerApi {
self: CallFunction<TransactionRecord>;
succeeds: CallFunction<TransactionRecord>;
}

export interface AssetRecord extends Horizon.BaseResponse {
asset_type: AssetType.credit4 | AssetType.credit12;
asset_code: string;
asset_issuer: string;
paging_token: string;
accounts: Horizon.AssetAccounts;
num_claimable_balances: number;
balances: Horizon.AssetBalances;
claimable_balances_amount: string;
amount: string;
num_accounts: number;
flags: Horizon.Flags;
}

export interface OrderbookRecord extends Horizon.BaseResponse {
bids: Array<{
price_r: {
Expand All @@ -422,7 +378,6 @@ export namespace ServerApi {
base: Asset;
counter: Asset;
}

export interface PaymentPathRecord extends Horizon.BaseResponse {
path: Array<{
asset_code: string;
Expand Down
5 changes: 5 additions & 0 deletions src/types/account.ts
@@ -0,0 +1,5 @@
export interface AccountRecordSigners {
key: string;
weight: number;
type: string;
}
22 changes: 22 additions & 0 deletions src/types/assets.ts
@@ -0,0 +1,22 @@
import { AssetType } from "stellar-base";
import { Horizon } from "./../horizon_api";

export interface OfferAsset {
asset_type: AssetType;
asset_code?: string;
asset_issuer?: string;
}

export interface AssetRecord extends Horizon.BaseResponse {
asset_type: AssetType.credit4 | AssetType.credit12;
asset_code: string;
asset_issuer: string;
paging_token: string;
accounts: Horizon.AssetAccounts;
num_claimable_balances: number;
balances: Horizon.AssetBalances;
claimable_balances_amount: string;
amount: string;
num_accounts: number;
flags: Horizon.Flags;
}

0 comments on commit 1b3c7fb

Please sign in to comment.