Skip to content

Commit

Permalink
adapts Block API for C-API v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Feb 18, 2021
1 parent cde3480 commit 07d0518
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ void chain_block_header(v8::FunctionCallbackInfo<v8::Value> const& args) {

Local<External> ret = External::New(isolate, header);
args.GetReturnValue().Set(ret);

}

void chain_block_transaction_count(v8::FunctionCallbackInfo<v8::Value> const& args) {
void chain_block_transactions(v8::FunctionCallbackInfo<v8::Value> const& args) {
Isolate* isolate = args.GetIsolate();

if (args.Length() != 1) {
Expand All @@ -89,8 +88,9 @@ void chain_block_transaction_count(v8::FunctionCallbackInfo<v8::Value> const& ar
void* vptr = v8::External::Cast(*args[0])->Value();
kth_block_t block = (kth_block_t)vptr;

uint64_t tx_count = kth_chain_block_transaction_count(block);
args.GetReturnValue().Set(Number::New(isolate, tx_count));
auto tx_list = kth_chain_block_transactions(block);
Local<External> ret = External::New(isolate, tx_list);
args.GetReturnValue().Set(ret);
}

void chain_block_serialized_size(v8::FunctionCallbackInfo<v8::Value> const& args) {
Expand Down Expand Up @@ -274,30 +274,6 @@ void chain_block_is_valid(v8::FunctionCallbackInfo<v8::Value> const& args) {
args.GetReturnValue().Set(Boolean::New(isolate, res != 0));
}

void chain_block_transaction_nth(v8::FunctionCallbackInfo<v8::Value> const& args) {
Isolate* isolate = args.GetIsolate();

if (args.Length() != 2) {
throw_exception(isolate, "Wrong number of arguments");
return;
}

if ( ! args[0]->IsExternal()) {
throw_exception(isolate, "Wrong arguments");
return;
}

if ( ! args[1]->IsNumber()) {
throw_exception(isolate, "Wrong arguments");
return;
}

void* vptr = v8::External::Cast(*args[0])->Value();
kth_block_t block = (kth_block_t)vptr;
uint64_t n = args[1]->IntegerValue(isolate->GetCurrentContext()).ToChecked();
kth_transaction_t res = kth_chain_block_transaction_nth(block, n);
args.GetReturnValue().Set(External::New(isolate, res));
}

void chain_block_signature_operations(v8::FunctionCallbackInfo<v8::Value> const& args) {
Isolate* isolate = args.GetIsolate();
Expand Down

0 comments on commit 07d0518

Please sign in to comment.