Implement accelerations API & config setting

This commit is contained in:
Mononaut
2023-05-30 19:51:11 -04:00
parent c246db1cf9
commit 20b3ceab1e
7 changed files with 43 additions and 1 deletions

View File

@@ -136,5 +136,9 @@
"trusted",
"servers"
]
},
"MEMPOOL_SERVICES": {
"API": "https://mempool.space/api",
"ACCELERATIONS": false
}
}

View File

@@ -127,5 +127,9 @@
"AUDIT": false,
"AUDIT_START_HEIGHT": 774000,
"SERVERS": []
},
"MEMPOOl_SERVICES": {
"API": "__MEMPOOL_SERVICES_API__",
"ACCELERATIONS": "__MEMPOOL_SERVICES_ACCELERATIONS__"
}
}

View File

@@ -127,6 +127,11 @@ describe('Mempool Backend Config', () => {
AUDIT_START_HEIGHT: 774000,
SERVERS: []
});
expect(config.MEMPOOL_SERVICES).toStrictEqual({
API: "",
ACCELERATIONS: false,
});
});
});
@@ -160,6 +165,8 @@ describe('Mempool Backend Config', () => {
expect(config.PRICE_DATA_SERVER).toStrictEqual(fixture.PRICE_DATA_SERVER);
expect(config.EXTERNAL_DATA_SERVER).toStrictEqual(fixture.EXTERNAL_DATA_SERVER);
expect(config.MEMPOOL_SERVICES).toStrictEqual(fixture.MEMPOOL_SERVICES);
});
});

View File

@@ -337,6 +337,10 @@ class Mempool {
}
public async $updateAccelerations(): Promise<string[]> {
if (!config.MEMPOOL_SERVICES.ACCELERATIONS) {
return [];
}
try {
const newAccelerations = await accelerationApi.fetchAccelerations$();

View File

@@ -137,7 +137,11 @@ interface IConfig {
AUDIT: boolean;
AUDIT_START_HEIGHT: number;
SERVERS: string[];
}
},
MEMPOOL_SERVICES: {
API: string;
ACCELERATIONS: boolean;
},
}
const defaults: IConfig = {
@@ -275,6 +279,10 @@ const defaults: IConfig = {
'AUDIT': false,
'AUDIT_START_HEIGHT': 774000,
'SERVERS': [],
},
'MEMPOOL_SERVICES': {
'API': '',
'ACCELERATIONS': false,
}
};
@@ -296,6 +304,7 @@ class Config implements IConfig {
EXTERNAL_DATA_SERVER: IConfig['EXTERNAL_DATA_SERVER'];
MAXMIND: IConfig['MAXMIND'];
REPLICATION: IConfig['REPLICATION'];
MEMPOOL_SERVICES: IConfig['MEMPOOL_SERVICES'];
constructor() {
const configs = this.merge(configFromFile, defaults);
@@ -316,6 +325,7 @@ class Config implements IConfig {
this.EXTERNAL_DATA_SERVER = configs.EXTERNAL_DATA_SERVER;
this.MAXMIND = configs.MAXMIND;
this.REPLICATION = configs.REPLICATION;
this.MEMPOOL_SERVICES = configs.MEMPOOL_SERVICES;
}
merge = (...objects: object[]): IConfig => {