@xyo-network/bridge 0.42.0 → 2.32.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +67 -8
- package/dist/cjs/Bridge.d.ts +10 -0
- package/dist/cjs/Bridge.d.ts.map +1 -0
- package/dist/{@types/index.js → cjs/Bridge.js} +1 -1
- package/dist/cjs/Bridge.js.map +1 -0
- package/dist/cjs/Config.d.ts +8 -0
- package/dist/cjs/Config.d.ts.map +1 -0
- package/dist/cjs/Config.js +5 -0
- package/dist/cjs/Config.js.map +1 -0
- package/dist/cjs/PartialBridgeConfig.d.ts +5 -0
- package/dist/cjs/PartialBridgeConfig.d.ts.map +1 -0
- package/dist/cjs/PartialBridgeConfig.js +3 -0
- package/dist/cjs/PartialBridgeConfig.js.map +1 -0
- package/dist/cjs/Queries/Connect.d.ts +8 -0
- package/dist/cjs/Queries/Connect.d.ts.map +1 -0
- package/dist/cjs/Queries/Connect.js +5 -0
- package/dist/cjs/Queries/Connect.js.map +1 -0
- package/dist/cjs/Queries/Disconnect.d.ts +8 -0
- package/dist/cjs/Queries/Disconnect.d.ts.map +1 -0
- package/dist/cjs/Queries/Disconnect.js +5 -0
- package/dist/cjs/Queries/Disconnect.js.map +1 -0
- package/dist/cjs/Queries/index.d.ts +8 -0
- package/dist/cjs/Queries/index.d.ts.map +1 -0
- package/dist/cjs/Queries/index.js +6 -0
- package/dist/cjs/Queries/index.js.map +1 -0
- package/dist/cjs/XyoBridge.d.ts +15 -0
- package/dist/cjs/XyoBridge.d.ts.map +1 -0
- package/dist/cjs/XyoBridge.js +40 -0
- package/dist/cjs/XyoBridge.js.map +1 -0
- package/dist/cjs/XyoBridgeWrapper.d.ts +7 -0
- package/dist/cjs/XyoBridgeWrapper.d.ts.map +1 -0
- package/dist/cjs/XyoBridgeWrapper.js +24 -0
- package/dist/cjs/XyoBridgeWrapper.js.map +1 -0
- package/dist/cjs/XyoHttpBridge.d.ts +28 -0
- package/dist/cjs/XyoHttpBridge.d.ts.map +1 -0
- package/dist/cjs/XyoHttpBridge.js +100 -0
- package/dist/cjs/XyoHttpBridge.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +5945 -0
- package/dist/esm/Bridge.d.ts +10 -0
- package/dist/esm/Bridge.d.ts.map +1 -0
- package/dist/esm/Bridge.js +2 -0
- package/dist/esm/Bridge.js.map +1 -0
- package/dist/esm/Config.d.ts +8 -0
- package/dist/esm/Config.d.ts.map +1 -0
- package/dist/esm/Config.js +2 -0
- package/dist/esm/Config.js.map +1 -0
- package/dist/esm/PartialBridgeConfig.d.ts +5 -0
- package/dist/esm/PartialBridgeConfig.d.ts.map +1 -0
- package/dist/esm/PartialBridgeConfig.js +2 -0
- package/dist/esm/PartialBridgeConfig.js.map +1 -0
- package/dist/esm/Queries/Connect.d.ts +8 -0
- package/dist/esm/Queries/Connect.d.ts.map +1 -0
- package/dist/esm/Queries/Connect.js +2 -0
- package/dist/esm/Queries/Connect.js.map +1 -0
- package/dist/esm/Queries/Disconnect.d.ts +8 -0
- package/dist/esm/Queries/Disconnect.d.ts.map +1 -0
- package/dist/esm/Queries/Disconnect.js +2 -0
- package/dist/esm/Queries/Disconnect.js.map +1 -0
- package/dist/esm/Queries/index.d.ts +8 -0
- package/dist/esm/Queries/index.d.ts.map +1 -0
- package/dist/esm/Queries/index.js +3 -0
- package/dist/esm/Queries/index.js.map +1 -0
- package/dist/esm/XyoBridge.d.ts +15 -0
- package/dist/esm/XyoBridge.d.ts.map +1 -0
- package/dist/esm/XyoBridge.js +29 -0
- package/dist/esm/XyoBridge.js.map +1 -0
- package/dist/esm/XyoBridgeWrapper.d.ts +7 -0
- package/dist/esm/XyoBridgeWrapper.d.ts.map +1 -0
- package/dist/esm/XyoBridgeWrapper.js +15 -0
- package/dist/esm/XyoBridgeWrapper.js.map +1 -0
- package/dist/esm/XyoHttpBridge.d.ts +28 -0
- package/dist/esm/XyoHttpBridge.d.ts.map +1 -0
- package/dist/esm/XyoHttpBridge.js +89 -0
- package/dist/esm/XyoHttpBridge.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +53 -42
- package/src/Bridge.ts +11 -0
- package/src/Config.ts +11 -0
- package/src/PartialBridgeConfig.ts +5 -0
- package/src/Queries/Connect.ts +9 -0
- package/src/Queries/Disconnect.ts +9 -0
- package/src/Queries/index.ts +11 -0
- package/src/XyoBridge.ts +43 -0
- package/src/XyoBridgeWrapper.ts +18 -0
- package/src/XyoHttpBridge.spec.ts +20 -0
- package/src/XyoHttpBridge.ts +112 -0
- package/src/index.ts +6 -2
- package/dist/@types/index.d.ts +0 -15
- package/dist/@types/index.d.ts.map +0 -1
- package/dist/@types/index.js.map +0 -1
- package/dist/app/index.d.ts +0 -1
- package/dist/app/index.d.ts.map +0 -1
- package/dist/app/index.js +0 -48
- package/dist/app/index.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/xyo-bridge-bound-witness-success-listener.d.ts +0 -20
- package/dist/xyo-bridge-bound-witness-success-listener.d.ts.map +0 -1
- package/dist/xyo-bridge-bound-witness-success-listener.js +0 -100
- package/dist/xyo-bridge-bound-witness-success-listener.js.map +0 -1
- package/dist/xyo-bridge-procedure-catalogue.d.ts +0 -9
- package/dist/xyo-bridge-procedure-catalogue.d.ts.map +0 -1
- package/dist/xyo-bridge-procedure-catalogue.js +0 -28
- package/dist/xyo-bridge-procedure-catalogue.js.map +0 -1
- package/dist/xyo-bridge.d.ts +0 -31
- package/dist/xyo-bridge.d.ts.map +0 -1
- package/dist/xyo-bridge.js +0 -130
- package/dist/xyo-bridge.js.map +0 -1
- package/src/@types/index.ts +0 -16
- package/src/app/index.ts +0 -55
- package/src/xyo-bridge-bound-witness-success-listener.ts +0 -108
- package/src/xyo-bridge-procedure-catalogue.ts +0 -33
- package/src/xyo-bridge.ts +0 -184
- package/tsconfig.json +0 -31
package/src/app/index.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// import { XyoLogger } from '@xyo-network/logger'
|
|
3
|
-
// import { XyoOriginBlockRepository } from '@xyo-network/origin-block-repository'
|
|
4
|
-
// import { XyoOriginChainLocalStorageRepository } from '@xyo-network/origin-chain'
|
|
5
|
-
// import { NobleScan } from '@xyo-network/ble.noble'
|
|
6
|
-
// import { serializer } from '@xyo-network/serializer'
|
|
7
|
-
// import { XyoBluetoothNetwork } from '@xyo-network/network.ble'
|
|
8
|
-
// import { XyoStorageBridgeQueueRepository } from '@xyo-network/bridge-queue-repository.keyvalue'
|
|
9
|
-
// import { XyoLevelDbStorageProvider } from '@xyo-network/storage.leveldb'
|
|
10
|
-
// import { getHashingProvider } from '@xyo-network/hashing'
|
|
11
|
-
// import { XyoClientTcpNetwork, IXyoNetworkAddressProvider, IXyoTCPNetworkAddress } from '@xyo-network/network.tcp'
|
|
12
|
-
// import { IXyoBridgeConfig } from '../@types'
|
|
13
|
-
// import { XyoBridge } from '../xyo-bridge'
|
|
14
|
-
|
|
15
|
-
// export const bridgeEntryPoint = async () => {
|
|
16
|
-
// const hasher = getHashingProvider('sha256')
|
|
17
|
-
// const scanner = new NobleScan()
|
|
18
|
-
// const bleNetwork = new XyoBluetoothNetwork(scanner)
|
|
19
|
-
// const storageProvider = new XyoLevelDbStorageProvider("./w4feef/")
|
|
20
|
-
// const bridgeQueueRepo = new XyoStorageBridgeQueueRepository(storageProvider)
|
|
21
|
-
// const blockRepo = new XyoOriginBlockRepository(storageProvider, serializer, hasher)
|
|
22
|
-
// const chainRepo = new XyoOriginChainLocalStorageRepository(storageProvider, blockRepo, serializer)
|
|
23
|
-
// const logger = new XyoLogger(false, false)
|
|
24
|
-
|
|
25
|
-
// const tcpPeers: IXyoNetworkAddressProvider = {
|
|
26
|
-
// next: async () => {
|
|
27
|
-
// const peer: IXyoTCPNetworkAddress = {
|
|
28
|
-
// host: "alpha-peers.xyo.network",
|
|
29
|
-
// port: 11000
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
// return peer
|
|
33
|
-
// }
|
|
34
|
-
// }
|
|
35
|
-
// const tcpClient = new XyoClientTcpNetwork(tcpPeers)
|
|
36
|
-
|
|
37
|
-
// const bridgeConfig: IXyoBridgeConfig = {
|
|
38
|
-
// hasher,
|
|
39
|
-
// storageProvider,
|
|
40
|
-
// bridgeQueueRepo,
|
|
41
|
-
// blockRepo,
|
|
42
|
-
// chainRepo,
|
|
43
|
-
// logger
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// const bridge = new XyoBridge(bleNetwork, tcpClient, bridgeConfig)
|
|
47
|
-
|
|
48
|
-
// await bridge.init()
|
|
49
|
-
|
|
50
|
-
// setTimeout(() => {
|
|
51
|
-
// bridge.start()
|
|
52
|
-
// }, 2000)
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// bridgeEntryPoint()
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: XY | The Findables Company <ryanxyo>
|
|
3
|
-
* @Date: Thursday, 7th February 2019 11:32:52 am
|
|
4
|
-
* @Email: developer@xyfindables.com
|
|
5
|
-
* @Filename: xyo-bound-witness-success-listener.ts
|
|
6
|
-
* @Last modified by: ryanxyo
|
|
7
|
-
* @Last modified time: Thursday, 7th February 2019 11:33:33 am
|
|
8
|
-
* @License: All Rights Reserved
|
|
9
|
-
* @Copyright: Copyright XY | The Findables Company
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { IXyoBoundWitnessSuccessListener, XyoNestedBoundWitnessExtractor } from "@xyo-network/peer-interaction"
|
|
13
|
-
import { IXyoBoundWitness, XyoBoundWitnessValidator, XyoBoundWitness, XyoFetter, XyoWitness, XyoKeySet, XyoSignatureSet } from "@xyo-network/bound-witness"
|
|
14
|
-
import { XyoBase } from "@xyo-network/base"
|
|
15
|
-
import { IXyoHashProvider } from "@xyo-network/hashing"
|
|
16
|
-
import { IXyoOriginChainRepository, XyoBridgeBlockSet } from "@xyo-network/origin-chain"
|
|
17
|
-
import { IXyoOriginBlockRepository } from "@xyo-network/origin-block-repository"
|
|
18
|
-
import { CatalogueItem } from "@xyo-network/network"
|
|
19
|
-
import { IXyoSerializableObject } from '@xyo-network/serialization'
|
|
20
|
-
import { XyoBridgeQueue, XyoBridgeOption } from '@xyo-network/bridge-queue-repository'
|
|
21
|
-
|
|
22
|
-
export class XyoBridgeBoundWitnessSuccessListener extends XyoBase implements IXyoBoundWitnessSuccessListener {
|
|
23
|
-
|
|
24
|
-
constructor (
|
|
25
|
-
private readonly hashingProvider: IXyoHashProvider,
|
|
26
|
-
private readonly boundWitnessValidator: XyoBoundWitnessValidator,
|
|
27
|
-
private readonly originChainRepository: IXyoOriginChainRepository,
|
|
28
|
-
private readonly originBlockRepository: IXyoOriginBlockRepository,
|
|
29
|
-
private readonly bridgeQueue: XyoBridgeQueue,
|
|
30
|
-
private readonly bridgeOption: XyoBridgeOption
|
|
31
|
-
) {
|
|
32
|
-
super()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async onBoundWitnessSuccess(boundWitness: IXyoBoundWitness, mutex: any, choice: CatalogueItem): Promise<void> {
|
|
36
|
-
const hashValue = await this.hashingProvider.createHash(boundWitness.getSigningData())
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
await this.boundWitnessValidator.validateBoundWitness(hashValue, boundWitness)
|
|
40
|
-
} catch (err) {
|
|
41
|
-
this.logError(`Origin block failed validation. Will not add.`, err)
|
|
42
|
-
throw err
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.bridgeQueue.addQueueItem(hashValue.serialize())
|
|
46
|
-
|
|
47
|
-
const removedSubItemsBlock = this.removeSubBoundWitnesses(boundWitness)
|
|
48
|
-
|
|
49
|
-
await this.originBlockRepository.addOriginBlock(hashValue, removedSubItemsBlock)
|
|
50
|
-
|
|
51
|
-
await this.boundWitnessValidator.validateBoundWitness(hashValue, boundWitness)
|
|
52
|
-
await this.originChainRepository.updateOriginChainState(hashValue, removedSubItemsBlock, mutex)
|
|
53
|
-
|
|
54
|
-
this.logInfo(`${hashValue.serializeHex()} added to Origin-Chain and Origin-Block-Repository`)
|
|
55
|
-
const nestedBoundWitnesses = new XyoNestedBoundWitnessExtractor().extractNestedBoundWitnesses(boundWitness)
|
|
56
|
-
|
|
57
|
-
await nestedBoundWitnesses.reduce(async (promiseChain, nestedBoundWitness) => {
|
|
58
|
-
await promiseChain
|
|
59
|
-
const nestedHashValue = await this.hashingProvider.createHash(nestedBoundWitness.getSigningData())
|
|
60
|
-
const nestedHash = nestedHashValue.serialize() as Buffer
|
|
61
|
-
this.logInfo(`Extracted nested block with hash ${nestedHash.toString('hex')}`)
|
|
62
|
-
|
|
63
|
-
const containsBlock = await this.originBlockRepository.containsOriginBlock(nestedHash)
|
|
64
|
-
if (!containsBlock) {
|
|
65
|
-
try {
|
|
66
|
-
this.bridgeQueue.addQueueItem(nestedHash)
|
|
67
|
-
await this.boundWitnessValidator.validateBoundWitness(nestedHashValue, nestedBoundWitness)
|
|
68
|
-
} catch (err) {
|
|
69
|
-
this.logError(`Origin block failed validation. Will not add.`, err)
|
|
70
|
-
throw err
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await this.originBlockRepository.addOriginBlock(nestedHashValue, nestedBoundWitness, hashValue)
|
|
74
|
-
}
|
|
75
|
-
}, Promise.resolve() as Promise<void>)
|
|
76
|
-
|
|
77
|
-
if (choice === CatalogueItem.TAKE_ORIGIN_CHAIN) {
|
|
78
|
-
this.bridgeOption.onCompleted()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private removeSubBoundWitnesses (boundWitness: IXyoBoundWitness): IXyoBoundWitness {
|
|
85
|
-
// tslint:disable-next-line:prefer-array-literal
|
|
86
|
-
const newBoundWitnessArray: Array<XyoFetter | XyoWitness> = []
|
|
87
|
-
|
|
88
|
-
boundWitness.fetterWitnesses.forEach((fOW) => {
|
|
89
|
-
if (fOW instanceof XyoWitness) {
|
|
90
|
-
const newItems: IXyoSerializableObject[] = []
|
|
91
|
-
const array = fOW.getData() as IXyoSerializableObject[]
|
|
92
|
-
|
|
93
|
-
array.forEach((item) => {
|
|
94
|
-
if (item.schemaObjectId !== XyoBridgeBlockSet.deserializer.schemaObjectId &&
|
|
95
|
-
item.schemaObjectId !== XyoSignatureSet.deserializer.schemaObjectId) {
|
|
96
|
-
newItems.push(item)
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
newBoundWitnessArray.push(new XyoWitness((fOW as XyoWitness).signatureSet, newItems))
|
|
101
|
-
} else if (fOW instanceof XyoFetter) {
|
|
102
|
-
newBoundWitnessArray.push(fOW as XyoFetter)
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
return new XyoBoundWitness(newBoundWitnessArray)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { IXyoNetworkProcedureCatalogue, CatalogueItem, IXyoNetworkProvider } from '@xyo-network/network'
|
|
3
|
-
|
|
4
|
-
export class XyoBrideProcedureCatalogue implements IXyoNetworkProcedureCatalogue {
|
|
5
|
-
|
|
6
|
-
constructor(private advertising: CatalogueItem[]) {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canDo (catalogueItem: CatalogueItem): boolean {
|
|
11
|
-
if (catalogueItem === CatalogueItem.GIVE_ORIGIN_CHAIN) {
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (catalogueItem === CatalogueItem.TAKE_ORIGIN_CHAIN) {
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (catalogueItem === CatalogueItem.BOUND_WITNESS) {
|
|
20
|
-
return true
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getCurrentCatalogue (): CatalogueItem[] {
|
|
27
|
-
return this.advertising
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public setCatalogue (catalogue: CatalogueItem[]): void {
|
|
31
|
-
throw Error("Bridge catalogue setting not supported")
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/xyo-bridge.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { serializer } from '@xyo-network/serializer'
|
|
3
|
-
import { getSignerProvider } from '@xyo-network/signing.ecdsa'
|
|
4
|
-
import { XyoBoundWitnessValidator } from '@xyo-network/bound-witness'
|
|
5
|
-
import { XyoBoundWitnessInteraction } from '@xyo-network/peer-interaction-handlers'
|
|
6
|
-
import { CatalogueItem, IXyoNetworkProvider } from '@xyo-network/network'
|
|
7
|
-
import { XyoBridgeQueue, XyoBridgeOption } from '@xyo-network/bridge-queue-repository'
|
|
8
|
-
import { IXyoBoundWitnessInteractionFactory, XyoBoundWitnessPayloadProvider, XyoBoundWitnessHandlerProvider } from '@xyo-network/peer-interaction'
|
|
9
|
-
import { XyoBridgeBoundWitnessSuccessListener } from './xyo-bridge-bound-witness-success-listener'
|
|
10
|
-
import { XyoPeerInteractionRouter } from '@xyo-network/peer-interaction-router'
|
|
11
|
-
import { XyoBrideProcedureCatalogue } from './xyo-bridge-procedure-catalogue'
|
|
12
|
-
import { XyoSimplePeerConnectionDelegate, XyoPeerConnectionHandler, IXyoCatalogueResolver } from '@xyo-network/peer-connections'
|
|
13
|
-
import { IXyoBridgeConfig } from './@types'
|
|
14
|
-
|
|
15
|
-
export class XyoBridge {
|
|
16
|
-
public bridgeEveryN = 10
|
|
17
|
-
public networkDelegate: XyoSimplePeerConnectionDelegate
|
|
18
|
-
public toNetworkDelegate: XyoSimplePeerConnectionDelegate
|
|
19
|
-
public bridgeQueue = new XyoBridgeQueue(this.bridgeConfig.bridgeQueueRepo)
|
|
20
|
-
|
|
21
|
-
public bridgeOption = new XyoBridgeOption(this.bridgeConfig.blockRepo, this.bridgeQueue, this.bridgeConfig.hasher)
|
|
22
|
-
public payloadProvider = new XyoBoundWitnessPayloadProvider()
|
|
23
|
-
private running = false
|
|
24
|
-
|
|
25
|
-
private networkCatResolver: IXyoCatalogueResolver = {
|
|
26
|
-
resolveCategory: (catalogueItems: CatalogueItem[]): CatalogueItem | undefined => {
|
|
27
|
-
|
|
28
|
-
for (const item of catalogueItems) {
|
|
29
|
-
if (item === CatalogueItem.GIVE_ORIGIN_CHAIN) {
|
|
30
|
-
return CatalogueItem.TAKE_ORIGIN_CHAIN
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (const item of catalogueItems) {
|
|
35
|
-
if (item === CatalogueItem.TAKE_ORIGIN_CHAIN) {
|
|
36
|
-
return CatalogueItem.GIVE_ORIGIN_CHAIN
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return CatalogueItem.BOUND_WITNESS
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private networkRouter = new XyoPeerInteractionRouter()
|
|
45
|
-
|
|
46
|
-
private boundWitnessValidator = new XyoBoundWitnessValidator()
|
|
47
|
-
|
|
48
|
-
private networkHandler = new XyoPeerConnectionHandler(this.networkRouter, this.networkCatResolver)
|
|
49
|
-
|
|
50
|
-
private success = new XyoBridgeBoundWitnessSuccessListener(
|
|
51
|
-
this.bridgeConfig.hasher,
|
|
52
|
-
this.boundWitnessValidator,
|
|
53
|
-
this.bridgeConfig.chainRepo,
|
|
54
|
-
this.bridgeConfig.blockRepo,
|
|
55
|
-
this.bridgeQueue,
|
|
56
|
-
this.bridgeOption
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
private interactionFactory: IXyoBoundWitnessInteractionFactory = {
|
|
60
|
-
newInstance: (signersForBoundWitness, payload) => {
|
|
61
|
-
return new XyoBoundWitnessInteraction(
|
|
62
|
-
signersForBoundWitness,
|
|
63
|
-
payload,
|
|
64
|
-
serializer,
|
|
65
|
-
CatalogueItem.BOUND_WITNESS
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private standardBoundWitnessHandlerProvider = new XyoBoundWitnessHandlerProvider(
|
|
71
|
-
this.bridgeConfig.chainRepo,
|
|
72
|
-
this.payloadProvider,
|
|
73
|
-
this.success,
|
|
74
|
-
this.interactionFactory
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
constructor(private bridgeFromNetwork: IXyoNetworkProvider,
|
|
78
|
-
private bridgeToNetwork: IXyoNetworkProvider,
|
|
79
|
-
private bridgeConfig: IXyoBridgeConfig) {
|
|
80
|
-
|
|
81
|
-
const bridgeProcedureCatalogueCollect = new XyoBrideProcedureCatalogue(
|
|
82
|
-
[
|
|
83
|
-
CatalogueItem.GIVE_ORIGIN_CHAIN,
|
|
84
|
-
CatalogueItem.TAKE_ORIGIN_CHAIN,
|
|
85
|
-
CatalogueItem.BOUND_WITNESS
|
|
86
|
-
]
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
const bridgeProcedureCatalogueSend = new XyoBrideProcedureCatalogue(
|
|
90
|
-
[
|
|
91
|
-
CatalogueItem.GIVE_ORIGIN_CHAIN,
|
|
92
|
-
CatalogueItem.TAKE_ORIGIN_CHAIN,
|
|
93
|
-
]
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
this.networkDelegate = new XyoSimplePeerConnectionDelegate(
|
|
97
|
-
bridgeFromNetwork,
|
|
98
|
-
bridgeProcedureCatalogueCollect,
|
|
99
|
-
this.networkHandler
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
this.toNetworkDelegate = new XyoSimplePeerConnectionDelegate(
|
|
103
|
-
bridgeToNetwork,
|
|
104
|
-
bridgeProcedureCatalogueSend,
|
|
105
|
-
this.networkHandler
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public mainBridgeLoop = async () => {
|
|
110
|
-
this.bridgeConfig.logger.info(`Bridge on new cycle`)
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const blePipe = await this.networkDelegate.provideConnection()
|
|
114
|
-
await this.networkDelegate.handlePeerConnection(blePipe)
|
|
115
|
-
|
|
116
|
-
if (await this.bridgeConfig.chainRepo.getIndex() % this.bridgeEveryN === 0) {
|
|
117
|
-
this.bridgeConfig.logger.info("Will try to bridge blocks")
|
|
118
|
-
|
|
119
|
-
const tcpPipe = await this.toNetworkDelegate.provideConnection()
|
|
120
|
-
await this.toNetworkDelegate.handlePeerConnection(tcpPipe)
|
|
121
|
-
await tcpPipe.close()
|
|
122
|
-
|
|
123
|
-
const blocksToRemove = this.bridgeQueue.getBlocksToRemove()
|
|
124
|
-
|
|
125
|
-
for (const block of blocksToRemove) {
|
|
126
|
-
await this.bridgeConfig.blockRepo.removeOriginBlock(block)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await this.bridgeConfig.bridgeQueueRepo.commit()
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
} catch (error) {
|
|
133
|
-
this.bridgeConfig.logger.error(`Uncaught error: ${error}`)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
this.bridgeConfig.logger.info(`Bridge has block height: ${await this.bridgeConfig.chainRepo.getIndex()}`)
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public async init() {
|
|
141
|
-
this.payloadProvider.addBoundWitnessOption(CatalogueItem.TAKE_ORIGIN_CHAIN, this.bridgeOption)
|
|
142
|
-
|
|
143
|
-
this.networkRouter.use(CatalogueItem.BOUND_WITNESS, () => {
|
|
144
|
-
return this.standardBoundWitnessHandlerProvider
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
this.networkRouter.use(CatalogueItem.TAKE_ORIGIN_CHAIN, () => {
|
|
148
|
-
return this.standardBoundWitnessHandlerProvider
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
this.networkRouter.use(CatalogueItem.GIVE_ORIGIN_CHAIN, () => {
|
|
152
|
-
return this.standardBoundWitnessHandlerProvider
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
await this.bridgeConfig.bridgeQueueRepo.restore()
|
|
156
|
-
|
|
157
|
-
if (await this.bridgeConfig.chainRepo.getIndex() === 0) {
|
|
158
|
-
const newSigner = getSignerProvider("secp256k1-sha256").newInstance()
|
|
159
|
-
|
|
160
|
-
this.bridgeConfig.logger
|
|
161
|
-
.info(`Creating first signer, has public key: ${newSigner.publicKey.getData().toString('hex')}`)
|
|
162
|
-
|
|
163
|
-
await this.bridgeConfig.chainRepo.setCurrentSigners([newSigner])
|
|
164
|
-
const boundWitness = await this.bridgeConfig.chainRepo.createGenesisBlock()
|
|
165
|
-
|
|
166
|
-
this.success.onBoundWitnessSuccess(boundWitness, undefined, CatalogueItem.BOUND_WITNESS)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public start () {
|
|
171
|
-
this.running = true
|
|
172
|
-
this.asyncLoop()
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
public stop () {
|
|
176
|
-
this.running = false
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private async asyncLoop () {
|
|
180
|
-
while (this.running) {
|
|
181
|
-
await this.mainBridgeLoop()
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es6",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["esnext"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"composite": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"noImplicitAny": true,
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"outDir": "dist",
|
|
15
|
-
"rootDir": "src"
|
|
16
|
-
},
|
|
17
|
-
"exclude": [
|
|
18
|
-
"node_modules",
|
|
19
|
-
"src/**/test/*",
|
|
20
|
-
"src/**/spec",
|
|
21
|
-
"src/**/*.spec.ts"
|
|
22
|
-
],
|
|
23
|
-
"include": ["src/**/*", "app/index.ts"],
|
|
24
|
-
"references": [
|
|
25
|
-
{"path": "../network.ble"},
|
|
26
|
-
{"path": "../peer-interaction"},
|
|
27
|
-
{"path": "../peer-interaction-handlers"},
|
|
28
|
-
{"path": "../bridge-queue-repository"},
|
|
29
|
-
{"path": "../bridge-queue-repository.keyvalue"}
|
|
30
|
-
]
|
|
31
|
-
}
|