Skip to content

Commit 8eccb43

Browse files
authored
Fix work report files' cid (#65)
* Fix work report files * Ignore node modules' lint * Fix lint ignore file * Remove precompile for command * ignore all js file
1 parent 3a9b7c6 commit 8eccb43

File tree

4 files changed

+6
-40
lines changed

4 files changed

+6
-40
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build/
2+
*.js

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
"lint": "gts lint",
1111
"clean": "gts clean",
1212
"compile": "tsc",
13-
"fix": "gts fix",
14-
"prepare": "yarn run compile",
15-
"pretest": "yarn run compile",
16-
"posttest": "yarn run lint"
13+
"fix": "gts fix"
1714
},
1815
"dependencies": {
1916
"@polkadot/api": "^3.3.1",

src/services/swork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {ApiPromise} from '@polkadot/api';
33
import {Request} from 'express';
44
import {KeyringPair} from '@polkadot/keyring/types';
5-
import {sendTx, queryToObj} from './util';
5+
import {sendTx, queryToObj, strToHex} from './util';
66
import {logger} from '../log';
77

88
/**
@@ -35,7 +35,7 @@ export async function reportWorks(
3535
const pk = '0x' + req.body['pub_key'];
3636
const fileParser = (file: any) => {
3737
const rst: [string, number, number] = [
38-
'0x' + file.hash,
38+
strToHex(file.cid),
3939
file.size,
4040
file.c_block_num,
4141
];

src/services/util.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,6 @@ export function sleep(time: number) {
114114
return new Promise(resolve => setTimeout(resolve, time));
115115
}
116116

117-
export function getHexValue(hexStr: string) {
118-
if (hexStr.substring(0, 2) !== '0x') {
119-
return null;
120-
}
121-
const realHexStr = hexStr.substring(2);
122-
const bytes = hexStrToBytes(realHexStr);
123-
124-
let result = '';
125-
if (bytes) {
126-
for (let i = 0; i < bytes.length; i++) {
127-
result += String.fromCharCode(bytes[i]);
128-
}
129-
}
130-
return result;
131-
}
132-
133117
/**
134118
* Private functions
135119
*/
@@ -149,22 +133,6 @@ function getAccountInfo(req: Request): [string, string] {
149133
return [backup, password];
150134
}
151135

152-
// Hex string to bytes
153-
function hexStrToBytes(str: string) {
154-
let pos = 0;
155-
let len = str.length;
156-
if (len % 2 !== 0) {
157-
return null;
158-
}
159-
160-
len /= 2;
161-
const hex = [];
162-
for (let i = 0; i < len; i++) {
163-
const s = str.substr(pos, 2);
164-
const v = parseInt(s, 16);
165-
hex.push(v);
166-
pos += 2;
167-
}
168-
169-
return hex;
136+
export function strToHex(str: string): string {
137+
return '0x' + Buffer.from(str).toString('hex');
170138
}

0 commit comments

Comments
 (0)