Skip to content

Commit

Permalink
Resolved conflict with effects
Browse files Browse the repository at this point in the history
  • Loading branch information
gzigzigzeo committed Apr 5, 2019
2 parents 9e746dc + 4698dee commit 6b3d689
Show file tree
Hide file tree
Showing 20 changed files with 843 additions and 22 deletions.
32 changes: 32 additions & 0 deletions src/datasource/horizon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SortOrder } from "../util/paging";
import {
HorizonAssetType,
IHorizonAssetData,
IHorizonEffectData,
IHorizonOperationData,
IHorizonOrderBookData,
IHorizonPaymentPathData,
Expand Down Expand Up @@ -281,6 +282,37 @@ export default class HorizonAPI extends RESTDataSource {
});
}

public async getEffects(limit = 10, order: SortOrder = SortOrder.DESC, cursor?: string): Promise<IHorizonEffectData[]> {
return this.request("effects", { limit, order, cursor, cacheTtl: 10 });
}

public async getTransactionEffects(
transactionId: string,
limit = 10,
order: SortOrder.DESC,
cursor?: string
): Promise<IHorizonEffectData[]> {
return this.request(`transactions/${transactionId}/effects`, { limit, order, cursor, cacheTtl: 10 });
}

public async getAccountEffects(
accountId: AccountID,
limit = 10,
order: SortOrder = SortOrder.DESC,
cursor?: string
): Promise<IHorizonEffectData[]> {
return this.request(`accounts/${accountId}/effects`, { limit, order, cursor, cacheTtl: 10 });
}

public async getLedgerEffects(
ledgerSeq: number,
limit = 10,
order: SortOrder = SortOrder.DESC,
cursor?: string
): Promise<IHorizonEffectData[]> {
return this.request(`ledgers/${ledgerSeq}/effects`, { limit, order, cursor, cacheTtl: 10 });
}

private async request(
url: string,
params: {
Expand Down
145 changes: 145 additions & 0 deletions src/datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ export type HorizonOpType =
| "manage_data"
| "bump_sequence";

type HorizonEffectType =
| "account_created"
| "account_removed"
| "account_credited"
| "account_debited"
| "account_thresholds_updated"
| "account_home_domain_updated"
| "account_flags_updated"
| "account_inflation_destination_updated"
| "signer_created"
| "signer_removed"
| "signer_updated"
| "trustline_created"
| "trustline_removed"
| "trustline_updated"
| "trustline_authorized"
| "trustline_deauthorized"
| "offer_created"
| "offer_removed"
| "offer_updated"
| "trade"
| "data_created"
| "data_removed"
| "data_updated"
| "sequence_bumped";

interface IBaseOperationData {
id: string;
paging_token: any;
Expand Down Expand Up @@ -225,3 +251,122 @@ export interface IHorizonTradeData {
d: number;
};
}
interface IBaseEffect {
id: string;
paging_token: string;
account: AccountID;
type: HorizonEffectType;
created_at: string;
}

interface IAccountCreatedEffect extends IBaseEffect {
starting_balance: string;
}

interface IAccountCreditedEffect extends IBaseEffect {
amount: string;
}

interface IAccountDebitedEffect extends IBaseEffect {
amount: string;
}

interface IAccountThresholdsUpdatedEffect extends IBaseEffect {
low_threshold: number;
med_threshold: number;
high_threshold: number;
}

interface IAccountHomeDomainUpdatedEffect extends IBaseEffect {
home_domain: string;
}

interface IAccountFlagsUpdatedEffect extends IBaseEffect {
auth_required_flag?: boolean;
auth_revokable_flag?: boolean;
}

interface ISequenceBumpedEffect extends IBaseEffect {
new_seq: number;
}

interface ISignerCreatedEffect extends IBaseEffect {
weight: number;
public_key: string;
key: string;
}

interface ISignerRemovedEffect extends IBaseEffect {
weight: number;
public_key: string;
key: string;
}

interface ISignerUpdatedEffect extends IBaseEffect {
weight: number;
public_key: string;
key: string;
}

interface ITrustlineCreatedEffect extends IBaseEffect {
asset_type: HorizonAssetType;
asset_code: AssetCode;
asset_issuer: AccountID;
limit: string;
}

interface ITrustlineRemovedEffect extends IBaseEffect {
asset_type: HorizonAssetType;
asset_code: AssetCode;
asset_issuer: AccountID;
limit: string;
}

interface ITrustlineUpdatedEffect extends IBaseEffect {
asset_type: HorizonAssetType;
asset_code: AssetCode;
asset_issuer: AccountID;
limit: string;
}

interface ITrustlineAuthorizedEffect extends IBaseEffect {
trustor: AccountID;
asset_type: HorizonAssetType;
asset_code?: AssetCode;
}

interface ITrustlineDeauthorizedEffect extends IBaseEffect {
trustor: AccountID;
asset_type: HorizonAssetType;
asset_code?: AssetCode;
}

interface ITradeEffect extends IBaseEffect {
seller: AccountID;
offer_id: number;
sold_amount: string;
sold_asset_type: HorizonAssetType;
sold_asset_code?: AssetCode;
sold_asset_issuer?: AccountID;
bought_amount: string;
bought_asset_type: HorizonAssetType;
bought_asset_code?: AssetCode;
bought_asset_issuer?: AccountID;
}

export type IHorizonEffectData = IAccountCreatedEffect &
IAccountCreditedEffect &
IAccountDebitedEffect &
IAccountThresholdsUpdatedEffect &
IAccountHomeDomainUpdatedEffect &
IAccountFlagsUpdatedEffect &
ISequenceBumpedEffect &
ISignerCreatedEffect &
ISignerRemovedEffect &
ISignerUpdatedEffect &
ITrustlineCreatedEffect &
ITrustlineRemovedEffect &
ITrustlineUpdatedEffect &
ITrustlineAuthorizedEffect &
ITrustlineDeauthorizedEffect &
ITradeEffect;
140 changes: 140 additions & 0 deletions src/model/effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { Asset } from "stellar-sdk";
import { AccountID } from "./";

export enum EffectKinds {
AccountCreated = "accountCreated",
AccountRemoved = "accountRemoved",
AccountCredited = "accountCredited",
AccountDebited = "accountDebited",
AccountThresholdsUpdated = "accountThresholdsUpdated",
AccountHomeDomainUpdated = "accountHomeDomainUpdated",
AccountFlagsUpdated = "accountFlagsUpdated",
AccountInflationDestinationUpdated = "accountInflationDestinationUpdated",
SignerCreated = "signerCreated",
SignerRemoved = "signerRemoved",
SignerUpdated = "signerUpdated",
TrustlineCreated = "trustlineCreated",
TrustlineRemoved = "trustlineRemoved",
TrustlineUpdated = "trustlineUpdated",
TrustlineAuthorized = "trustlineAuthorized",
TrustlineDeauthorized = "trustlineDeauthorized",
OfferCreated = "offerCreated",
OfferRemoved = "offerRemoved",
OfferUpdated = "offerUpdated",
Trade = "trade",
DataCreated = "dataCreated",
DataRemoved = "dataRemoved",
DataUpdated = "dataUpdated",
SequenceBumped = "sequenceBumped"
}

export interface IBaseEffect {
id: string;
account: AccountID;
kind: EffectKinds;
createdAt: Date;
}

export interface IAccountCreatedEffect extends IBaseEffect {
startingBalance: string;
}

export interface IAccountCreditedEffect extends IBaseEffect {
amount: string;
}

export interface IAccountDebitedEffect extends IBaseEffect {
amount: string;
}

export interface IAccountThresholdsUpdatedEffect extends IBaseEffect {
lowThreshold: number;
medThreshold: number;
highThreshold: number;
}

export interface IAccountHomeDomainUpdatedEffect extends IBaseEffect {
homeDomain: string;
}

export interface IAccountFlagsUpdatedEffect extends IBaseEffect {
authRequiredFlag?: boolean;
authRevokableFlag?: boolean;
}

export interface ISignerCreatedEffect extends IBaseEffect {
weight: number;
publicKey: AccountID;
key: AccountID;
}

export interface ISignerRemovedEffect extends IBaseEffect {
weight: number;
publicKey: AccountID;
key: AccountID;
}

export interface ISignerUpdatedEffect extends IBaseEffect {
weight: number;
publicKey: AccountID;
key: AccountID;
}

export interface ITrustlineCreatedEffect extends IBaseEffect {
asset: Asset;
limit: string;
}

export interface ITrustlineRemovedEffect extends IBaseEffect {
asset: Asset;
limit: string;
}

export interface ITrustlineUpdatedEffect extends IBaseEffect {
asset: Asset;
limit: string;
}

export interface ITrustlineAuthorizedEffect extends IBaseEffect {
trustor: AccountID;
asset: Asset;
}

export interface ITrustlineDeauthorizedEffect extends IBaseEffect {
trustor: AccountID;
asset: Asset;
}

export interface ITradeEffect extends IBaseEffect {
seller: AccountID;
offerId: string;
soldAmount: string;
soldAsset: Asset;
boughtAmount: string;
boughtAsset: Asset;
}

export interface ISequenceBumpEffect extends IBaseEffect {
newSeq: number;
}

export type Effect =
| IAccountCreatedEffect
| IAccountCreditedEffect
| IAccountDebitedEffect
| IAccountThresholdsUpdatedEffect
| IAccountThresholdsUpdatedEffect
| IAccountHomeDomainUpdatedEffect
| IAccountFlagsUpdatedEffect
| ISignerCreatedEffect
| ISignerCreatedEffect
| ISignerRemovedEffect
| ISignerUpdatedEffect
| ITrustlineCreatedEffect
| ITrustlineRemovedEffect
| ITrustlineUpdatedEffect
| ITrustlineAuthorizedEffect
| ITrustlineAuthorizedEffect
| ITrustlineDeauthorizedEffect
| ITradeEffect
| ISequenceBumpEffect;
2 changes: 1 addition & 1 deletion src/model/factories/asset_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class AssetFactory {
return type === XDR.AssetType.assetTypeNative().value ? Asset.native() : new Asset(code, issuer);
}

public static fromHorizonResponse(type: HorizonAssetType, code: string, issuer: string) {
public static fromHorizonResponse(type: HorizonAssetType, code?: string, issuer?: string) {
return type === "native" ? Asset.native() : new Asset(code, issuer);
}

Expand Down
Loading

0 comments on commit 6b3d689

Please sign in to comment.