Skip to content

Commit a98ec98

Browse files
authored
Fix/improve sdk (#603)
* feat: add doc store * fix: improve the add doc error * fix: use github runner * fix: add protobuf
1 parent c2414a4 commit a98ec98

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131

3232
coverage:
3333
name: test
34-
#runs-on: ubuntu-latest
35-
runs-on: [self-hosted, linux, x64]
34+
runs-on: ubuntu-latest
35+
#runs-on: [self-hosted, linux, x64]
3636
steps:
3737
- name: Checkout repository
3838
uses: actions/checkout@v3
@@ -51,8 +51,8 @@ jobs:
5151
- name: Setup Build env
5252
run: |
5353
ROOT_DIR=`pwd`
54-
#sudo apt-get install protobuf-compiler -y
55-
#yarn global add arlocal_db3
54+
sudo apt-get install protobuf-compiler -y
55+
yarn global add arlocal_db3
5656
cd ${ROOT_DIR}/metadata && yarn install
5757
cd ${ROOT_DIR}/metadata && npx hardhat test
5858
test -e ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/DB3MetaStore.json && cp -f ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/DB3MetaStore.json ${ROOT_DIR}/abi/

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ members = [
1010
"src/sdk",
1111
"src/event"
1212
]
13-
1413
[workspace.dependencies]
1514
fastcrypto = {git = "https://github.com/MystenLabs/fastcrypto", rev = "306465d4fe04f6c26359d885f3b0a548b661de40"}
1615
ethers = {git="https://github.com/imotai/ethers-rs", rev="d526191b7972e8cf4412fee8b71cbf42e0ce7995"}

sdk/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export type {
3131
MutationResult,
3232
QueryResult,
3333
} from './store/types'
34-
export { addDoc, updateDoc, deleteDoc, queryDoc, getDoc } from './store/document_v2'
34+
export {
35+
addDoc,
36+
updateDoc,
37+
deleteDoc,
38+
queryDoc,
39+
getDoc,
40+
} from './store/document_v2'
3541

3642
export { SystemConfig, SystemStatus, Version } from './proto/db3_base'
3743
export {

sdk/src/store/document_v2.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ export async function updateDoc(
225225
}
226226
}
227227

228+
/**
229+
* Add a document to the collection.
230+
*
231+
* @param col The collection to add the document to.
232+
* @param doc The document to add.
233+
* @returns The ID of the newly added document.
234+
*/
228235
export async function addDoc(col: Collection, doc: DocumentData) {
229236
const documentMutation: DocumentMutation = {
230237
collectionName: col.name,
@@ -250,6 +257,7 @@ export async function addDoc(col: Collection, doc: DocumentData) {
250257
payload,
251258
col.db.client.nonce.toString()
252259
)
260+
253261
if (response.code == 0 && response.items.length > 0) {
254262
col.db.client.nonce += 1
255263
return {
@@ -259,6 +267,8 @@ export async function addDoc(col: Collection, doc: DocumentData) {
259267
id: response.items[0].value,
260268
}
261269
} else {
262-
throw new Error('fail to create collection')
270+
throw new Error(
271+
'fail to addDoc, maybe you can syncAccountNonce to resolve the problem'
272+
)
263273
}
264274
}

sdk/tests/client_v2.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
deleteDoc,
3737
updateDoc,
3838
queryDoc,
39-
getDoc
39+
getDoc,
4040
} from '../src/store/document_v2'
4141
import {
4242
createFromPrivateKey,
@@ -383,7 +383,7 @@ describe('test db3.js client module', () => {
383383
try {
384384
const doc = await getDoc(collection, 1000000000000)
385385
except(1).toBe(0)
386-
} catch(e) {}
386+
} catch (e) {}
387387
}
388388

389389
{

src/node/src/rollup_executor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,15 @@ impl RollupExecutor {
270270
return Ok(());
271271
}
272272
let now = Instant::now();
273+
273274
info!(
274275
"the next rollup start block {} and the newest block {current_block}",
275276
last_end_block
276277
);
278+
277279
self.pending_start_block
278280
.store(last_end_block, Ordering::Relaxed);
281+
279282
self.pending_end_block
280283
.store(current_block, Ordering::Relaxed);
281284
let mutations = self
@@ -305,6 +308,7 @@ impl RollupExecutor {
305308
self.pending_data_size.store(0, Ordering::Relaxed);
306309
self.pending_mutations.store(0, Ordering::Relaxed);
307310
}
311+
308312
let (id, reward, num_rows, size) = ar_toolbox
309313
.compress_and_upload_record_batch(
310314
tx,
@@ -318,13 +322,15 @@ impl RollupExecutor {
318322
let (evm_cost, tx_hash) = meta_store
319323
.update_rollup_step(id.as_str(), network_id)
320324
.await?;
325+
321326
let tx_str = format!("0x{}", hex::encode(tx_hash.as_bytes()));
322327

323328
info!("the process rollup done with num mutations {num_rows}, raw data size {memory_size}, compress data size {size} and processed time {} id {} ar cost {} and evm tx {} and cost {}", now.elapsed().as_secs(),
324329
id.as_str(), reward,
325330
tx_str.as_str(),
326331
evm_cost.as_u64()
327332
);
333+
328334
let record = RollupRecord {
329335
end_block: current_block,
330336
raw_data_size: memory_size as u64,
@@ -338,6 +344,7 @@ impl RollupExecutor {
338344
evm_tx: tx_str,
339345
evm_cost: evm_cost.as_u64(),
340346
};
347+
341348
self.storage
342349
.add_rollup_record(&record)
343350
.map_err(|e| DB3Error::RollupError(format!("{e}")))?;

0 commit comments

Comments
 (0)