Skip to content

Commit

Permalink
Refactor by cmdopt
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Nov 1, 2023
1 parent 21c216b commit 5913b49
Show file tree
Hide file tree
Showing 8 changed files with 552 additions and 100 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ LDFLAGS += -Ldeps/compiler-rt-builtins-riscv/build -lcompiler-rt
OBJDIR=build

QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o \
$(OBJDIR)/cutils.o $(OBJDIR)/mocked.o $(OBJDIR)/std_module.o $(OBJDIR)/ckb_module.o $(OBJDIR)/ckb_cell_fs.o $(OBJDIR)/libbf.o
$(OBJDIR)/cutils.o $(OBJDIR)/mocked.o $(OBJDIR)/std_module.o $(OBJDIR)/ckb_module.o $(OBJDIR)/ckb_cell_fs.o \
$(OBJDIR)/libbf.o $(OBJDIR)/cmdopt.o

STD_OBJS=$(OBJDIR)/string_impl.o $(OBJDIR)/malloc_impl.o $(OBJDIR)/math_impl.o \
$(OBJDIR)/math_log_impl.o $(OBJDIR)/math_pow_impl.o $(OBJDIR)/printf_impl.o $(OBJDIR)/stdio_impl.o \
Expand Down Expand Up @@ -79,7 +80,7 @@ test:

benchmark:
make -f tests/benchmark/Makefile

clean:
rm -f build/*.o
rm -f build/ckb-js-vm
Expand Down
14 changes: 14 additions & 0 deletions quickjs/ckb_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ int js_init_module_ckb(JSContext *ctx) {
#define JS_LOADER_ARGS_SIZE 2
#define BLAKE2B_BLOCK_SIZE 32

int load_cell_code_info_explicit(size_t *buf_size, size_t *index, const uint8_t* code_hash, uint8_t hash_type) {
int err = 0;
*index = 0;
err = ckb_look_for_dep_with_hash2(code_hash, hash_type, index);
CHECK(err);

*buf_size = 0;
err = ckb_load_cell_data(NULL, buf_size, 0, *index, CKB_SOURCE_CELL_DEP);
CHECK(err);
CHECK2(*buf_size > 0, -1);
exit:
return err;
}

int load_cell_code_info(size_t *buf_size, size_t *index) {
int err = 0;
unsigned char script[SCRIPT_SIZE];
Expand Down
1 change: 1 addition & 0 deletions quickjs/ckb_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
int js_init_module_ckb(JSContext *ctx);
int read_local_file(char *buf, int size);

int load_cell_code_info_explicit(size_t *buf_size, size_t *index, const uint8_t* code_hash, uint8_t hash_type);
int load_cell_code_info(size_t *buf_size, size_t *index);
int load_cell_code(size_t buf_size, size_t index, uint8_t *buf);

Expand Down
Loading

0 comments on commit 5913b49

Please sign in to comment.