Skip to content

Commit

Permalink
fix datavalue of dataavailability
Browse files Browse the repository at this point in the history
  • Loading branch information
Phong authored and Phong committed Jun 11, 2024
1 parent 129c6a6 commit 7edd302
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DB_NAME=squid_avail_turing
DB_PORT=23799
GQL_PORT=3001
GQL_PORT=3000
NETWORK=testnet
RPC_ENDPOINT=wss://turing-rpc.availspace.app
ARCHIVE_LOOKUP_NAME_TESTNET=data-avail
Expand Down
6 changes: 4 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ type Remark @entity {
blockNumber: Int! @index
sender: Account
fee: Amount
rawValue: String
dataRaw: String
dataValue: String
}

type DataAvailability @entity {
Expand All @@ -270,6 +271,7 @@ type DataAvailability @entity {
blockNumber: Int! @index
sender: Account
fee: Amount
rawValue: String
dataRaw: String
dataValue: String
isJson: Boolean
}
5 changes: 4 additions & 1 deletion src/model/generated/dataAvailability.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export class DataAvailability {
fee!: Amount | undefined | null

@Column_("text", {nullable: true})
rawValue!: string | undefined | null
dataRaw!: string | undefined | null

@Column_("text", {nullable: true})
dataValue!: string | undefined | null

@Column_("bool", {nullable: true})
isJson!: boolean | undefined | null
Expand Down
5 changes: 4 additions & 1 deletion src/model/generated/remark.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ export class Remark {
fee!: Amount | undefined | null

@Column_("text", {nullable: true})
rawValue!: string | undefined | null
dataRaw!: string | undefined | null

@Column_("text", {nullable: true})
dataValue!: string | undefined | null
}
17 changes: 12 additions & 5 deletions src/process/dataAvailabilityHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export class DataAvailabilityHandler implements IHandler {
symbol: "AVL",
decimal: 18
}

const idExist = this.availabilityData.get(call.id);

const dataValue = decodeData(call.args.data);
if(!idExist){
this.availabilityData.set(call.id, new DataAvailability({
id: call.id,
Expand All @@ -28,8 +27,9 @@ export class DataAvailabilityHandler implements IHandler {
blockNumber: call.extrinsic!.block.height,
sender: accountInstance.getAccountId(addressHex),
fee: new Amount(fee),
rawValue: await decodeData(call.args.data),
isJson: await isJson(call.args) ? true : false
dataRaw: call.args.data,
dataValue: dataValue,
isJson: isJson(dataValue) ? true : false
}));
}
}
Expand All @@ -52,11 +52,18 @@ function decodeData(str:string):string {
let strInput = str.slice(2, str.length);
const bytesData:Buffer = Buffer.from(strInput, 'hex');
let res = bytesData.toString().replace(/<Buffer |>/g, '');
if(isValidHexString(res)) return res;
if (isValidHexString(res)) return res;
else if (isJson(res)) return res;
else if (isValidString(res)) return res;
else return str;
}

function isValidHexString(str:string):boolean {
const hexRegex = /^0x[0-9A-Fa-f]+$/;
return hexRegex.test(str);
}

function isValidString(str: string): boolean {
const regex = /^[\x20-\x7E]*$/;
return regex.test(str);
}
3 changes: 2 additions & 1 deletion src/process/remarkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class RemarkHandler implements IHandler {
blockNumber: call.extrinsic!.block.height,
sender: accountInstance.getAccountId(addressHex),
fee:new Amount(fee),
rawValue: call.args.remark,
dataRaw: call.args.remark,
dataValue: call.args.remark,
}));
}
}
Expand Down

0 comments on commit 7edd302

Please sign in to comment.