-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: TejasvOnly <[email protected]>
- Loading branch information
1 parent
fd26063
commit 8286aa7
Showing
88 changed files
with
2,443 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@cypherock/coin-support-xrp': major | ||
'@cypherock/cysync-core-constants': patch | ||
'@cypherock/coin-support': patch | ||
'@cypherock/cysync-core': patch | ||
'@cypherock/coins': patch | ||
'@cypherock/cysync-ui': patch | ||
'@cypherock/cysync-cli': patch | ||
--- | ||
|
||
Added XRP support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['@cypherock/eslint-config/browser'], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig.eslint.json'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.turbo | ||
dist | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@cypherock/prettier-config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Coin Support XRP | ||
|
||
- All coin operations related to XRP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const baseConfig = require('@cypherock/jest-config/node'); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name": "@cypherock/coin-support-xrp", | ||
"version": "0.0.0", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"license": "AGPL-3.0", | ||
"private": true, | ||
"scripts": { | ||
"lint": "eslint --ext .ts,tsx,js,jsx src/ --fix", | ||
"lint:check": "eslint --ext .ts,tsx,js,jsx src/", | ||
"pretty": "prettier --write \"src/**/*.ts?(x)\" \"tests/**/*.ts?(x)\"", | ||
"pretty:check": "prettier --check \"src/**/*.ts?(x)\" \"tests/**/*.ts?(x)\"", | ||
"build": "rimraf dist && pnpm build:esm && pnpm build:cjs", | ||
"build:cjs": "tsc -p tsconfig_cjs.json", | ||
"build:esm": "tsc -p tsconfig.json", | ||
"build:dirty": "pnpm build:esm", | ||
"test": "jest", | ||
"pre-commit": "lint-staged" | ||
}, | ||
"devDependencies": { | ||
"@cypherock/eslint-config": "workspace:^", | ||
"@cypherock/jest-config": "workspace:^", | ||
"@cypherock/prettier-config": "workspace:^", | ||
"@cypherock/tsconfig": "workspace:^", | ||
"@jest/globals": "^29.5.0", | ||
"@stryker-mutator/core": "^7.0.2", | ||
"@stryker-mutator/jest-runner": "^7.0.2", | ||
"@stryker-mutator/typescript-checker": "^7.0.2", | ||
"@types/jest": "^29.5.2", | ||
"@types/lodash": "^4.14.195", | ||
"@types/multicoin-address-validator": "^0.5.0", | ||
"@types/node": "18.15.11", | ||
"eslint": "^8.43.0", | ||
"jest": "^29.5.0", | ||
"lint-staged": "^13.2.2", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.1", | ||
"ts-jest": "^29.1.0", | ||
"typescript": "^4.9.5", | ||
"xrpl": "^4.0.0" | ||
}, | ||
"dependencies": { | ||
"@cypherock/coin-support-interfaces": "workspace:^", | ||
"@cypherock/coin-support-utils": "workspace:^", | ||
"@cypherock/coins": "workspace:^", | ||
"@cypherock/cysync-interfaces": "workspace:^", | ||
"@cypherock/cysync-utils": "workspace:^", | ||
"@cypherock/db-interfaces": "workspace:^", | ||
"@cypherock/sdk-app-xrp": "^1.0.0", | ||
"@cypherock/sdk-interfaces": "^0.0.15", | ||
"@cypherock/sdk-utils": "^0.0.18", | ||
"lodash": "^4.17.21", | ||
"multicoin-address-validator": "^0.5.12", | ||
"rxjs": "^7.8.1" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx}": [ | ||
"eslint --ext ts,tsx --quiet --fix --", | ||
"prettier --write" | ||
], | ||
"*.{js,jsx,md,mdx,mjs,yml,yaml,css,json}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { getEnvVariable } from '@cypherock/cysync-utils'; | ||
|
||
export const config = { | ||
API_CYPHEROCK: getEnvVariable('API_CYPHEROCK', 'https://api.cypherock.com'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
import { | ||
CoinSupport, | ||
ICreateAccountEvent, | ||
ICreateAccountParams, | ||
IFormatAddressParams, | ||
IGetAccountHistoryParams, | ||
IGetAccountHistoryResult, | ||
IGetCoinAllocationsParams, | ||
IGetCoinAllocationsResult, | ||
IGetExplorerLink, | ||
IInitializeTransactionParams, | ||
IPreparedTransaction, | ||
IReceiveEvent, | ||
IReceiveParams, | ||
ISignMessageEvent, | ||
ISignMessageParams, | ||
ISignTransactionParams, | ||
ISyncAccountsParams, | ||
ISyncPriceHistoriesParams, | ||
ISyncPricesParams, | ||
IValidateAddressParams, | ||
} from '@cypherock/coin-support-interfaces'; | ||
import { ITransaction } from '@cypherock/db-interfaces'; | ||
import { setXrpLib } from '@cypherock/sdk-app-xrp'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import * as operations from './operations'; | ||
import { | ||
IBroadcastXrpTransactionParams, | ||
IPrepareXrpTransactionParams, | ||
ISignXrpTransactionEvent, | ||
} from './operations/types'; | ||
import { setCoinSupportXrpLib, XrpLibType } from './utils'; | ||
|
||
export * from './operations/types'; | ||
export { updateLogger } from './utils/logger'; | ||
|
||
export class XrpSupport implements CoinSupport { | ||
public static setXrpLib(xrplib: XrpLibType): void { | ||
setXrpLib(xrplib); | ||
setCoinSupportXrpLib(xrplib); | ||
} | ||
|
||
public receive(params: IReceiveParams): Observable<IReceiveEvent> { | ||
return operations.receive(params); | ||
} | ||
|
||
public createAccounts( | ||
params: ICreateAccountParams, | ||
): Observable<ICreateAccountEvent> { | ||
return operations.createAccounts(params); | ||
} | ||
|
||
public syncAccount(params: ISyncAccountsParams): Observable<void> { | ||
return operations.syncAccount(params); | ||
} | ||
|
||
public async initializeTransaction( | ||
params: IInitializeTransactionParams, | ||
): Promise<IPreparedTransaction> { | ||
return operations.initializeTransaction(params); | ||
} | ||
|
||
public async prepareTransaction( | ||
params: IPrepareXrpTransactionParams, | ||
): Promise<IPreparedTransaction> { | ||
return operations.prepareTransaction(params); | ||
} | ||
|
||
public signTransaction( | ||
params: ISignTransactionParams, | ||
): Observable<ISignXrpTransactionEvent> { | ||
return operations.signTransaction(params); | ||
} | ||
|
||
public broadcastTransaction( | ||
params: IBroadcastXrpTransactionParams, | ||
): Promise<ITransaction> { | ||
return operations.broadcastTransaction(params); | ||
} | ||
|
||
public signMessage( | ||
params: ISignMessageParams, | ||
): Observable<ISignMessageEvent> { | ||
throw new Error(`Method not implemented Params: ${params}`); | ||
} | ||
|
||
public getCoinAllocations( | ||
params: IGetCoinAllocationsParams, | ||
): Promise<IGetCoinAllocationsResult> { | ||
return operations.getCoinAllocations(params); | ||
} | ||
|
||
public getAccountHistory( | ||
params: IGetAccountHistoryParams, | ||
): Promise<IGetAccountHistoryResult> { | ||
return operations.getAccountHistory(params); | ||
} | ||
|
||
public validateAddress(params: IValidateAddressParams): boolean { | ||
return operations.validateAddress(params); | ||
} | ||
|
||
public syncPrices(params: ISyncPricesParams): Observable<void> { | ||
return operations.syncPrices(params); | ||
} | ||
|
||
public syncPriceHistories( | ||
params: ISyncPriceHistoriesParams, | ||
): Observable<void> { | ||
return operations.syncPriceHistories(params); | ||
} | ||
|
||
public getExplorerLink(params: IGetExplorerLink): string { | ||
return operations.getExplorerLink(params); | ||
} | ||
|
||
public formatAddress(params: IFormatAddressParams): string { | ||
return params.address; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/coin-support-xrp/src/operations/broadcastTransaction/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
getAccountAndCoin, | ||
insertOrUpdateTransactions, | ||
} from '@cypherock/coin-support-utils'; | ||
import { xrpCoinList } from '@cypherock/coins'; | ||
import { BigNumber } from '@cypherock/cysync-utils'; | ||
import { | ||
ITransaction, | ||
TransactionStatusMap, | ||
TransactionTypeMap, | ||
} from '@cypherock/db-interfaces'; | ||
|
||
import { IBroadcastXrpTransactionParams } from './types'; | ||
|
||
import { broadcastTransactionToBlockchain } from '../../services'; | ||
import { deriveAddress } from '../../utils'; | ||
|
||
export const broadcastTransaction = async ( | ||
params: IBroadcastXrpTransactionParams, | ||
): Promise<ITransaction> => { | ||
const { db, signedTransaction, transaction } = params; | ||
const { account, coin } = await getAccountAndCoin( | ||
db, | ||
xrpCoinList, | ||
transaction.accountId, | ||
); | ||
|
||
const myAddress = deriveAddress(account.xpubOrAddress); | ||
const isMine = params.transaction.computedData.output.address === myAddress; | ||
|
||
const result = await broadcastTransactionToBlockchain( | ||
signedTransaction, | ||
coin.id, | ||
); | ||
|
||
const parsedTransaction: ITransaction = { | ||
hash: result.tx_json.hash, | ||
fees: transaction.computedData.fees, | ||
amount: '0', | ||
status: TransactionStatusMap.pending, | ||
type: TransactionTypeMap.send, | ||
timestamp: Date.now(), | ||
blockHeight: -1, | ||
inputs: [ | ||
{ | ||
address: myAddress, | ||
amount: '0', | ||
isMine: true, | ||
}, | ||
], | ||
outputs: [ | ||
{ | ||
...params.transaction.userInputs.outputs[0], | ||
isMine, | ||
}, | ||
], | ||
confirmations: 0, | ||
accountId: account.__id, | ||
walletId: account.walletId, | ||
assetId: account.assetId, | ||
parentAssetId: account.parentAssetId, | ||
familyId: account.familyId, | ||
parentAccountId: account.parentAccountId, | ||
remarks: [transaction.userInputs.outputs[0].remarks ?? ''], | ||
extraData: { | ||
destinationTag: result.tx_json.DestinationTag, | ||
flags: result.tx_json.Flags, | ||
sequence: result.tx_json.Sequence, | ||
lastLedgerSequence: result.tx_json.LastLedgerSequence, | ||
}, | ||
}; | ||
|
||
const amount = parsedTransaction.outputs.reduce( | ||
(sum, output) => (output.isMine ? sum : sum.plus(output.amount)), | ||
new BigNumber(0), | ||
); | ||
parsedTransaction.amount = amount.abs().toString(); | ||
parsedTransaction.inputs[0].amount = amount.abs().toString(); | ||
|
||
const [addedTxn] = await insertOrUpdateTransactions(db, [parsedTransaction]); | ||
|
||
return addedTxn; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/coin-support-xrp/src/operations/broadcastTransaction/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IBroadcastTransactionParams } from '@cypherock/coin-support-interfaces'; | ||
|
||
import { IPreparedXrpTransaction } from '../transaction'; | ||
|
||
export interface IBroadcastXrpTransactionParams | ||
extends IBroadcastTransactionParams<string> { | ||
transaction: IPreparedXrpTransaction; | ||
} |
Oops, something went wrong.