Skip to content

Commit 40624d5

Browse files
Merge pull request #18 from interlay/theo/fix-oracle-currencies
fix: broken oracle update decoding with the new currency refactor
2 parents 2fc66fd + fc592da commit 40624d5

7 files changed

Lines changed: 48 additions & 15 deletions

File tree

.env

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1+
# #localhost
12
# ARCHIVE_ENDPOINT=http://localhost:4010/v1/graphql
23
# CHAIN_ENDPOINT=ws://localhost:9944
3-
ARCHIVE_ENDPOINT=https://api-kusama.interlay.io/gateway-graphql/v1/graphql
4-
CHAIN_ENDPOINT=wss://api-kusama.interlay.io/parachain
54

6-
PROCESS_FROM=540000
5+
# #Interlay (mainnet)
6+
# TOADD: urls
7+
# SS58_CODEC="interlay"
8+
# BITCOIN_NETWORK='mainnet'
9+
10+
# #Kintsugi (mainnet)
11+
# ARCHIVE_ENDPOINT=https://api-kusama.interlay.io/gateway-graphql/v1/graphql
12+
# CHAIN_ENDPOINT=wss://api-kusama.interlay.io/parachain
13+
# PROCESS_FROM=540000
14+
# SS58_CODEC="kintsugi"
15+
# BITCOIN_NETWORK='mainnet'
16+
17+
# #Interlay (testnet)
18+
# TOADD: urls
19+
# SS58_CODEC="interlay"
20+
# BITCOIN_NETWORK='testnet'
21+
22+
#Kintsugi (testnet)
23+
ARCHIVE_ENDPOINT=https://api-dev-kintsugi.interlay.io/gateway-graphql/v1/graphql
24+
CHAIN_ENDPOINT=wss://api-dev-kintsugi.interlay.io/parachain
25+
PROCESS_FROM=44800
726
SS58_CODEC="kintsugi"
27+
BITCOIN_NETWORK='testnet'
28+
829

930
# Params config
10-
BITCOIN_NETWORK='mainnet'
1131

1232
# DB config
1333
DB_NAME=indexer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = class oraclecurrency1660849179124 {
2+
name = 'oraclecurrency1660849179124'
3+
4+
async up(db) {
5+
await db.query(`ALTER TABLE "oracle_update" DROP COLUMN "type_key"`)
6+
await db.query(`ALTER TABLE "oracle_update" ADD "type_key" jsonb`)
7+
}
8+
9+
async down(db) {
10+
await db.query(`ALTER TABLE "oracle_update" ADD "type_key" text`)
11+
await db.query(`ALTER TABLE "oracle_update" DROP COLUMN "type_key"`)
12+
}
13+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "interbtc-indexer",
33
"private": "true",
4-
"version": "0.8.0",
4+
"version": "0.9.0",
55
"description": "GraphQL server and Substrate indexer for the interBTC parachain",
66
"author": "",
77
"license": "ISC",

schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ type OracleUpdate @entity {
178178
timestamp: DateTime!
179179
oracleId: String!
180180
type: OracleUpdateType!
181-
typeKey: String
181+
typeKey: Currency
182182
updateValue: BigInt!
183183
}
184184

src/mappings/event/oracle.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ export async function feedValues(ctx: EventHandlerContext): Promise<void> {
3333
});
3434
let keyToString = key.__kind.toString();
3535
if (key.__kind === "ExchangeRate") {
36-
const typeString = useLegacyCurrency
36+
const exchangeCurrency = useLegacyCurrency
3737
? legacyCurrencyId
38-
.encode(key.value as CurrencyId_V15)
39-
.toString()
40-
: currencyId.encode(key.value as CurrencyId_V17).toString();
41-
update.typeKey = typeString;
42-
keyToString += typeString;
38+
.encode(key.value as CurrencyId_V15)
39+
: currencyId.encode(key.value as CurrencyId_V17);
40+
update.typeKey = exchangeCurrency;
41+
keyToString += JSON.stringify(exchangeCurrency);
4342
}
4443
update.id = `${oracleAddress}-${height.absolute.toString()}-${keyToString}`;
4544
await ctx.store.save(update);

src/model/generated/_nativeToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class NativeToken {
99
constructor(props?: Partial<Omit<NativeToken, 'toJSON'>>, json?: any) {
1010
Object.assign(this, props)
1111
if (json != null) {
12-
this._token = marshal.string.fromJSON(json.token) as Token // MANUALLY EDITED
12+
this._token = marshal.string.fromJSON(json.token) as Token
1313
}
1414
}
1515

src/model/generated/oracleUpdate.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, M
22
import * as marshal from "./marshal"
33
import {Height} from "./height.model"
44
import {OracleUpdateType} from "./_oracleUpdateType"
5+
import {Currency, fromJsonCurrency} from "./_currency"
56

67
@Entity_()
78
export class OracleUpdate {
@@ -25,8 +26,8 @@ export class OracleUpdate {
2526
@Column_("varchar", {length: 13, nullable: false})
2627
type!: OracleUpdateType
2728

28-
@Column_("text", {nullable: true})
29-
typeKey!: string | undefined | null
29+
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.toJSON(), from: obj => obj == null ? undefined : fromJsonCurrency(obj)}, nullable: true})
30+
typeKey!: Currency | undefined | null
3031

3132
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
3233
updateValue!: bigint

0 commit comments

Comments
 (0)