Skip to content

Commit

Permalink
Core Refactor (#75)
Browse files Browse the repository at this point in the history
* packaging: add uuid lib

* feat: implement conveyour belt class

* refactor: conveyor belts structure

* feat: add build transaction pipeline

* feat: add generic plugin factory

* feat: add conveyor belts

* feat: add conveyor belt error extractor

* feat: add profiler plugin

* feat: add debug plugin

* feat: add plugins

* feat: add fee bump plugin

* feat: add build transaction pipeline errors

* feat: add classic sign req pipeline

* refactor: dump

* fix: dump

* feat: add soroban get transaction pipeline

* feat: add extract wrapped contract id

* refactor: wrap asset and deploy

* refactor: wrap and deploy function clean up

* refactor: deploy contract

* refactor: structure

* feat: add multibelt pipeline

* feat: add read from contract

* feat: add profiler fee extraction

* feat: add auto restore

* feat: auto restore bump

* refactor: contract engine clean up

* feat: add channel accounts plugin

* feat: add classic transaction pipeline

* feat: add channel accounts plugin

* refactor: classic transaction pipeline

* feat: classic and SAC

* feat: add trustline in classic assets

* feat: add channel accounts utils

* refactor: cleanup

* refactor: exports

* remove: old tests

* remove: deprecated tests

* fix: circular dependency

* fix: undefined spec

* refactor: network to networkconfig

* feat: restore code and instance

* feat: add errors to soroban get transaction

* fix: remove unused error codes

* feat: add classic sign requirements errors

* packaging: bump stellar sdk version

* feat: add export to contract spec

* fix: auto restore bump sequence

* fix: auto restore timeout

* style: tests and contract engine

* packaging: bump version to v0.6.0
  • Loading branch information
fazzatti authored Feb 1, 2024
1 parent 5db075a commit 2dcdb50
Show file tree
Hide file tree
Showing 113 changed files with 3,682 additions and 3,659 deletions.
75 changes: 55 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-plus",
"version": "0.5.7",
"version": "0.6.0",
"description": "beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -27,6 +27,7 @@
"devDependencies": {
"@types/jest": "^29.5.10",
"@types/node": "^20.10.0",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"eslint": "^8.55.0",
Expand All @@ -50,8 +51,8 @@
},
"dependencies": {
"@stellar/freighter-api": "^1.7.1",
"@stellar/stellar-sdk": "^11.1.0",
"axios": "^1.6.2",
"stellar-base": "^10.0.1"
"@stellar/stellar-sdk": "^11.2.1",
"uuid": "^9.0.1"
}
}
54 changes: 0 additions & 54 deletions src/stellar-plus/account/account-handler/default/default.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/stellar-plus/account/account-handler/default/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DefaultAccountHandlerClient extends AccountBaseClient implements De
*
* @args payload - The payload for the account handler. Additional parameters may be provided to enable different helpers.
* @param {string=} payload.secretKey The secret key of the account. If not provided, a new random account will be created.
* @param {Network} payload.network The network to use.
* @param {NetworkConfig} payload.networkConfig The network to use.
* @description - The default account handler is used for handling and creating new accounts by directly manipulating the secret key.
*/
constructor(payload: DefaultAccountHandlerPayload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
mockSignedClassicTransactionXdr,
mockUnsignedClassicTransaction,
} from 'stellar-plus/test/mocks/classic-transaction'
import { Network } from 'stellar-plus/types'
import { NetworkConfig } from 'stellar-plus/types'

jest.mock('@stellar/freighter-api', () => ({
getPublicKey: jest.fn(),
Expand All @@ -18,7 +18,7 @@ jest.mock('@stellar/freighter-api', () => ({
}))

const mockPublicKey = 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
const mockNetwork = testnet as Network
const mockNetwork = testnet as NetworkConfig

const mockFreighterGetPublicKey = (): void => {
;(freighterApi.getPublicKey as jest.MockedFunction<typeof freighterApi.getPublicKey>).mockResolvedValue(mockPublicKey)
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('FreighterAccountHandlerClient', () => {
let client: FreighterAccountHandlerClient

beforeEach(() => {
client = new FreighterAccountHandlerClient({ network: mockNetwork })
client = new FreighterAccountHandlerClient({ networkConfig: mockNetwork })
})

it('should initialize with provided network', () => {
Expand Down
16 changes: 8 additions & 8 deletions src/stellar-plus/account/account-handler/freighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ import {
FreighterCallback,
} from 'stellar-plus/account/account-handler/freighter/types'
import { AccountBaseClient } from 'stellar-plus/account/base'
import { Network } from 'stellar-plus/types'
import { NetworkConfig } from 'stellar-plus/types'

import { FAHError } from './errors'

export class FreighterAccountHandlerClient extends AccountBaseClient implements FreighterAccountHandler {
private network: Network
private networkConfig: NetworkConfig

/**
*
* @args payload - The payload for the Freighter account handler. Additional parameters may be provided to enable different helpers.
*
* @param {Network} payload.network The network to use.
* @param {NetworkConfig} payload.networkConfig The network to use.
*
* @description - The Freighter account handler is used for handling and creating new accounts by integrating with the browser extension Freighter App.
*/
constructor(payload: FreighterAccHandlerPayload) {
const { network } = payload as { network: Network }
const { networkConfig } = payload as { networkConfig: NetworkConfig }
const publicKey = ''
super({ ...payload, publicKey })

this.network = network
this.networkConfig = networkConfig
this.publicKey = ''
}

Expand Down Expand Up @@ -111,7 +111,7 @@ export class FreighterAccountHandlerClient extends AccountBaseClient implements
const txXDR = tx.toXDR()

const signedTx = await signTransaction(txXDR, {
networkPassphrase: this.network.networkPassphrase,
networkPassphrase: this.networkConfig.networkPassphrase,
accountToSign: this.publicKey,
})
return signedTx
Expand Down Expand Up @@ -197,8 +197,8 @@ export class FreighterAccountHandlerClient extends AccountBaseClient implements
public async isNetworkCorrect(): Promise<boolean> {
const networkDetails = await getNetworkDetails()

if (networkDetails.networkPassphrase !== this.network.networkPassphrase) {
throw FAHError.connectedToWrongNetworkError(this.network.name)
if (networkDetails.networkPassphrase !== this.networkConfig.networkPassphrase) {
throw FAHError.connectedToWrongNetworkError(this.networkConfig.name)
}
return true
}
Expand Down
4 changes: 2 additions & 2 deletions src/stellar-plus/account/account-handler/freighter/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountHandler, AccountHandlerPayload } from 'stellar-plus/account/account-handler/types'
import { Network } from 'stellar-plus/types'
import { NetworkConfig } from 'stellar-plus/types'

export type FreighterAccountHandler = AccountHandler & {
connect(onPublicKeyReceived: FreighterCallback): Promise<void>
Expand All @@ -12,7 +12,7 @@ export type FreighterAccountHandler = AccountHandler & {
}

export type FreighterAccHandlerPayload = AccountHandlerPayload & {
network: Network
networkConfig: NetworkConfig
}

export type FreighterCallback = (pk: string) => Promise<void>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ import { AccountHelpersPayload } from 'stellar-plus/account/helpers/types'
import { TransactionXdr } from 'stellar-plus/types'

export type AccountHandler = AccountBase & {
getPublicKey(): string
sign(tx: Transaction | FeeBumpTransaction): Promise<TransactionXdr> | TransactionXdr
signatureSchema?: SignatureSchema
}

export type AccountHandlerPayload = AccountHelpersPayload

export type SignatureSchema = {
threasholds: {
low: number
medium: number
high: number
}
signers: {
weight: number
publicKey: string
}[]
}
5 changes: 2 additions & 3 deletions src/stellar-plus/account/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { AccountBase, AccountBasePayload } from 'stellar-plus/account/base/types'
import { AccountHelpers } from 'stellar-plus/account/helpers'
import { TransactionProcessor } from 'stellar-plus/core/classic-transaction-processor'

export class AccountBaseClient extends AccountHelpers implements AccountBase {
protected publicKey: string
// helpers: AccountHelpers
private transactionProcessor?: TransactionProcessor

/**
*
* @args {} payload - The payload for the account. Additional parameters may be provided to enable different helpers.
* @param {string} payload.publicKey The public key of the account.
* @param {Network=} payload.network The network to use.
* @param {NetworkConfig=} payload.networkConfig The network to use.
*
* @description - The base account is used for handling accounts with no management actions.
*/
Expand Down
Loading

0 comments on commit 2dcdb50

Please sign in to comment.