Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86a0dn0k3 - Ethereum Support Implementation #15

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 54 additions & 34 deletions common/config/rush/npm-shrinkwrap.json

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

2 changes: 1 addition & 1 deletion packages/blockchain-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cityofzion/blockchain-service",
"version": "0.6.0",
"version": "0.7.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/CityOfZion/blockchain-services",
Expand Down
22 changes: 6 additions & 16 deletions packages/blockchain-service/src/BSAgreggator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockchainAlreadyExist, InvalidBlockchainService } from './exceptions'
import { BlockchainService, Claimable } from "./interfaces";
import { BlockchainService } from "./interfaces";
export class BSAgreggator<BSCustom extends BlockchainService = BlockchainService, BSCustomName extends string = string> {
readonly blockchainservices: Record<BSCustomName, BSCustom>
private bsList: BlockchainService<BSCustomName>[]
Expand Down Expand Up @@ -32,17 +32,17 @@ export class BSAgreggator<BSCustom extends BlockchainService = BlockchainService

validateTextAllBlockchains(text: string) {
if (this.haveBlockchainServices()) throw new InvalidBlockchainService(JSON.stringify(this.blockchainservices))
return this.bsList.some(bs => [bs.validateAddress(text), bs.validateEncryptedKey(text), bs.validateWif(text)].some(it => it === true))
return this.bsList.some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true))
}

validateWifAllBlockchains(wif: string) {
if (this.haveBlockchainServices()) throw new InvalidBlockchainService(JSON.stringify(this.blockchainservices))
return this.bsList.some(bs => bs.validateWif(wif))
return this.bsList.some(bs => bs.validateKey(wif))
}

validateEncryptedKeyAllBlockchains(encryptedKey: string) {
if (this.haveBlockchainServices()) throw new InvalidBlockchainService(JSON.stringify(this.blockchainservices))
return this.bsList.some(bs => bs.validateEncryptedKey(encryptedKey))
return this.bsList.some(bs => bs.validateEncrypted(encryptedKey))
}

getBlockchainByAddress(address: string): BlockchainService<BSCustomName> | null {
Expand All @@ -52,21 +52,11 @@ export class BSAgreggator<BSCustom extends BlockchainService = BlockchainService

getBlockchainByWif(wif: string): BlockchainService<BSCustomName> | null {
if (this.haveBlockchainServices()) throw new InvalidBlockchainService(JSON.stringify(this.blockchainservices))
return this.bsList.find(bs => bs.validateWif(wif)) ?? null
return this.bsList.find(bs => bs.validateKey(wif)) ?? null
}

getBlockchainByEncryptedKey(encryptedKey: string): BlockchainService<BSCustomName> | null {
if (this.haveBlockchainServices()) throw new InvalidBlockchainService(JSON.stringify(this.blockchainservices))
return this.bsList.find(bs => bs.validateEncryptedKey(encryptedKey)) ?? null
}

getBlockchainsClaimable() {
const methodName = { claim: 'claim', getUnclaimed: 'getUnclaimed', tokenClaim: 'tokenClaim' }
const claimableBlockchains = this.bsList.filter(
blockchain => methodName.claim in blockchain &&
methodName.getUnclaimed in blockchain.dataService &&
methodName.tokenClaim in blockchain
) as Array<BlockchainService<BSCustomName> & Claimable>
return claimableBlockchains
return this.bsList.find(bs => bs.validateEncrypted(encryptedKey)) ?? null
}
}
14 changes: 9 additions & 5 deletions packages/blockchain-service/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { BlockchainService, CalculableFee, Claimable, NeoNameService } from './interfaces'
import { BlockchainService, BSCalculableFee, BSClaimable, BSWithNameService, BSWithNft } from './interfaces'

export function hasNNS(service: BlockchainService): service is NeoNameService & BlockchainService {
export function hasNameService(service: BlockchainService): service is BSWithNameService & BlockchainService {
return 'getNNSRecord' in service && 'getOwnerOfNNS' in service && 'validateNNSFormat' in service
}

export function isClaimable(service: BlockchainService): service is Claimable & BlockchainService {
return 'claim' in service && 'tokenClaim' in service && 'getUnclaimed' in service.dataService
export function isClaimable(service: BlockchainService): service is BSClaimable & BlockchainService {
return 'claim' in service && 'claimToken' in service && 'getUnclaimed' in service.blockchainDataService
}

export function isCalculableFee(service: BlockchainService): service is CalculableFee & BlockchainService {
export function isCalculableFee(service: BlockchainService): service is BSCalculableFee & BlockchainService {
return 'calculateTransferFee' in service
}

export function hasNft(service: BlockchainService): service is BSWithNft & BlockchainService {
return 'nftDataService' in service
}
Loading