Skip to content

Commit

Permalink
Merge pull request #15 from CityOfZion/CU-86a0dn0k3
Browse files Browse the repository at this point in the history
CU-86a0dn0k3 - Ethereum Support Implementation
  • Loading branch information
melanke authored Aug 30, 2023
2 parents a51c6b9 + 3f18764 commit a88e120
Show file tree
Hide file tree
Showing 54 changed files with 2,269 additions and 790 deletions.
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

0 comments on commit a88e120

Please sign in to comment.