Skip to content

Commit

Permalink
Merge pull request LedgerHQ#30 from phaazon/release/2.0.0-rc.20
Browse files Browse the repository at this point in the history
Bump version v2.0.0-rc.21.
  • Loading branch information
KhalilBellakrid authored Feb 19, 2019
2 parents d1d715a + 673476a commit 9c21ab4
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 92 deletions.
5 changes: 4 additions & 1 deletion include/DatabaseResultRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace ledger { namespace core { namespace api {

class DatabaseBlob;

/** A table of data representing a database query result, which is usually generated by executing a statement that queries the database. */
/**
* A table of data representing a database query result, which is usually generated by executing a statement that queries the database.
* DatabaseResultRow instances are not expected to live once DatabaseResultSet::next has been called on its parent result set.
*/
class DatabaseResultRow {
public:
virtual ~DatabaseResultRow() {}
Expand Down
25 changes: 11 additions & 14 deletions include/DatabaseResultSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace ledger { namespace core { namespace api {
class DatabaseError;
class DatabaseResultRow;

/** ResultSet is a cursor over a query result. It allows user to iterate through query rows. */
/**
* ResultSet is a cursor over a query result. It allows user to iterate through query rows. When you start iterating through
* result the cursor is placed before the first element of the set.
*/
class DatabaseResultSet {
public:
virtual ~DatabaseResultSet() {}
Expand All @@ -34,28 +37,22 @@ class DatabaseResultSet {
virtual int32_t getUpdateCount() = 0;

/**
* Get the number of row retrieved
* @return The number of rows retrieved by the query
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
virtual int32_t getRowNumber() = 0;
virtual bool hasNext() = 0;

/**
* Returns the number of remaining rows to get before the end of the result set.
* @return The number of rows remaining rows to get before the end of the result set.
* Returns the number of remaining rows before the result set needs to load more rows
* @return The number of remaining rows before the result set needs to load more rows.
*/
virtual int32_t available() = 0;

/**
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
virtual bool hasNext() = 0;

/**
* Move the result set to the next available result. This method may fail if there is now further row to fetch.
* Internally move the result set to the next available row. This method may fail if there is no further row to fetch.
* @return Return a result set pointing to the next row.
*/
virtual std::shared_ptr<DatabaseResultSet> next() = 0;
virtual void next() = 0;

/** Close the result set. */
virtual void close() = 0;
Expand Down
11 changes: 11 additions & 0 deletions include/WalletPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ class LIBCORE_EXPORT WalletPool {
* The return value is always true and doesn’t convey any useful information for now.
*/
virtual void freshResetAll(const std::shared_ptr<ErrorCodeCallback> & callback) = 0;

/**
* Change Database password.
*
* Allow to change password of database holding all informations about
* accounts, wallets, transactions ...
*
* WARNING: be carefull to have no other instances of WalletPool using
* same database
*/
virtual void changePassword(const std::string & oldPassword, const std::string & newPassword, const std::shared_ptr<ErrorCodeCallback> & callback) = 0;
};

} } } // namespace ledger::core::api
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/ledger-core",
"version": "2.0.0-rc.20",
"version": "2.0.0-rc.21",
"description": "Ledger Core Library cross-platform C++ bindings for NodeJs",
"main": "js/index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion preinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import urllib
import os

libCoreVersion = "2.5.0-rc"
libCoreVersion = "2.6.0-rc-ceff37"

baseURL = "https://s3-eu-west-1.amazonaws.com/ledger-lib-ledger-core"
filePath = ""
Expand Down
46 changes: 10 additions & 36 deletions src/NJSDatabaseResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@ int32_t NJSDatabaseResultSet::getUpdateCount()
return fResult_getUpdateCount;
}

int32_t NJSDatabaseResultSet::getRowNumber()
bool NJSDatabaseResultSet::hasNext()
{
Nan::HandleScope scope;
//Wrap parameters
Handle<Value> args[1];
Local<Object> local_njs_impl = Nan::New<Object>(njs_impl);
if(!local_njs_impl->IsObject())
{
Nan::ThrowError("NJSDatabaseResultSet::getRowNumber fail to retrieve node implementation");
Nan::ThrowError("NJSDatabaseResultSet::hasNext fail to retrieve node implementation");
}
auto calling_funtion = Nan::Get(local_njs_impl,Nan::New<String>("getRowNumber").ToLocalChecked()).ToLocalChecked();
auto result_getRowNumber = Nan::CallAsFunction(calling_funtion->ToObject(),local_njs_impl,0,args);
if(result_getRowNumber.IsEmpty())
auto calling_funtion = Nan::Get(local_njs_impl,Nan::New<String>("hasNext").ToLocalChecked()).ToLocalChecked();
auto result_hasNext = Nan::CallAsFunction(calling_funtion->ToObject(),local_njs_impl,0,args);
if(result_hasNext.IsEmpty())
{
Nan::ThrowError("NJSDatabaseResultSet::getRowNumber call failed");
Nan::ThrowError("NJSDatabaseResultSet::hasNext call failed");
}
auto checkedResult_getRowNumber = result_getRowNumber.ToLocalChecked();
auto fResult_getRowNumber = Nan::To<int32_t>(checkedResult_getRowNumber).FromJust();
return fResult_getRowNumber;
auto checkedResult_hasNext = result_hasNext.ToLocalChecked();
auto fResult_hasNext = Nan::To<bool>(checkedResult_hasNext).FromJust();
return fResult_hasNext;
}

int32_t NJSDatabaseResultSet::available()
Expand All @@ -94,28 +94,7 @@ int32_t NJSDatabaseResultSet::available()
return fResult_available;
}

bool NJSDatabaseResultSet::hasNext()
{
Nan::HandleScope scope;
//Wrap parameters
Handle<Value> args[1];
Local<Object> local_njs_impl = Nan::New<Object>(njs_impl);
if(!local_njs_impl->IsObject())
{
Nan::ThrowError("NJSDatabaseResultSet::hasNext fail to retrieve node implementation");
}
auto calling_funtion = Nan::Get(local_njs_impl,Nan::New<String>("hasNext").ToLocalChecked()).ToLocalChecked();
auto result_hasNext = Nan::CallAsFunction(calling_funtion->ToObject(),local_njs_impl,0,args);
if(result_hasNext.IsEmpty())
{
Nan::ThrowError("NJSDatabaseResultSet::hasNext call failed");
}
auto checkedResult_hasNext = result_hasNext.ToLocalChecked();
auto fResult_hasNext = Nan::To<bool>(checkedResult_hasNext).FromJust();
return fResult_hasNext;
}

std::shared_ptr<DatabaseResultSet> NJSDatabaseResultSet::next()
void NJSDatabaseResultSet::next()
{
Nan::HandleScope scope;
//Wrap parameters
Expand All @@ -131,11 +110,6 @@ std::shared_ptr<DatabaseResultSet> NJSDatabaseResultSet::next()
{
Nan::ThrowError("NJSDatabaseResultSet::next call failed");
}
auto checkedResult_next = result_next.ToLocalChecked();
Local<Object> njs_fResult_next = checkedResult_next->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
auto fResult_next = djinni::js::ObjectWrapper<DatabaseResultSet>::Unwrap(njs_fResult_next);

return fResult_next;
}

void NJSDatabaseResultSet::close()
Expand Down
38 changes: 13 additions & 25 deletions src/NJSDatabaseResultSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,22 @@ class NJSDatabaseResultSet: public ledger::core::api::DatabaseResultSet {
int32_t getUpdateCount();

/**
* Get the number of row retrieved
* @return The number of rows retrieved by the query
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
int32_t getRowNumber();
bool hasNext();

/**
* Returns the number of remaining rows to get before the end of the result set.
* @return The number of rows remaining rows to get before the end of the result set.
* Returns the number of remaining rows before the result set needs to load more rows
* @return The number of remaining rows before the result set needs to load more rows.
*/
int32_t available();

/**
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
bool hasNext();

/**
* Move the result set to the next available result. This method may fail if there is now further row to fetch.
* Internally move the result set to the next available row. This method may fail if there is no further row to fetch.
* @return Return a result set pointing to the next row.
*/
std::shared_ptr<DatabaseResultSet> next();
void next();

/** Close the result set. */
void close();
Expand All @@ -84,25 +78,19 @@ class NJSDatabaseResultSet: public ledger::core::api::DatabaseResultSet {
static NAN_METHOD(getUpdateCount);

/**
* Get the number of row retrieved
* @return The number of rows retrieved by the query
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
static NAN_METHOD(getRowNumber);
static NAN_METHOD(hasNext);

/**
* Returns the number of remaining rows to get before the end of the result set.
* @return The number of rows remaining rows to get before the end of the result set.
* Returns the number of remaining rows before the result set needs to load more rows
* @return The number of remaining rows before the result set needs to load more rows.
*/
static NAN_METHOD(available);

/**
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
static NAN_METHOD(hasNext);

/**
* Move the result set to the next available result. This method may fail if there is now further row to fetch.
* Internally move the result set to the next available row. This method may fail if there is no further row to fetch.
* @return Return a result set pointing to the next row.
*/
static NAN_METHOD(next);
Expand Down
30 changes: 30 additions & 0 deletions src/NJSWalletPoolCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,35 @@ NAN_METHOD(NJSWalletPool::freshResetAll) {
cpp_impl->freshResetAll(arg_0);
info.GetReturnValue().Set(arg_0_resolver->GetPromise());
}
NAN_METHOD(NJSWalletPool::changePassword) {

//Check if method called with right number of arguments
if(info.Length() != 2)
{
return Nan::ThrowError("NJSWalletPool::changePassword needs 2 arguments");
}

//Check if parameters have correct types
String::Utf8Value string_arg_0(info[0]->ToString());
auto arg_0 = std::string(*string_arg_0);
String::Utf8Value string_arg_1(info[1]->ToString());
auto arg_1 = std::string(*string_arg_1);

//Create promise and set it into Callback
auto arg_2_resolver = v8::Promise::Resolver::New(Nan::GetCurrentContext()).ToLocalChecked();
NJSErrorCodeCallback *njs_ptr_arg_2 = new NJSErrorCodeCallback(arg_2_resolver);
std::shared_ptr<NJSErrorCodeCallback> arg_2(njs_ptr_arg_2);


//Unwrap current object and retrieve its Cpp Implementation
auto cpp_impl = djinni::js::ObjectWrapper<WalletPool>::Unwrap(info.This());
if(!cpp_impl)
{
return Nan::ThrowError("NJSWalletPool::changePassword : implementation of WalletPool is not valid");
}
cpp_impl->changePassword(arg_0,arg_1,arg_2);
info.GetReturnValue().Set(arg_2_resolver->GetPromise());
}

NAN_METHOD(NJSWalletPool::New) {
//Only new allowed
Expand Down Expand Up @@ -723,6 +752,7 @@ void NJSWalletPool::Initialize(Local<Object> target) {
Nan::SetPrototypeMethod(func_template,"getEventBus", getEventBus);
Nan::SetPrototypeMethod(func_template,"eraseDataSince", eraseDataSince);
Nan::SetPrototypeMethod(func_template,"freshResetAll", freshResetAll);
Nan::SetPrototypeMethod(func_template,"changePassword", changePassword);
Nan::SetPrototypeMethod(func_template,"isNull", isNull);
//Set object prototype
WalletPool_prototype.Reset(objectTemplate);
Expand Down
11 changes: 11 additions & 0 deletions src/NJSWalletPoolCpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ class NJSWalletPool final {
*/
static NAN_METHOD(freshResetAll);

/**
* Change Database password.
*
* Allow to change password of database holding all informations about
* accounts, wallets, transactions ...
*
* WARNING: be carefull to have no other instances of WalletPool using
* same database
*/
static NAN_METHOD(changePassword);

static NAN_METHOD(New);

static NAN_METHOD(isNull);
Expand Down
39 changes: 25 additions & 14 deletions src/ledgercore_doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,10 @@ declare class NJSDatabaseColumn
declare function getType(): DatabaseValueType;
declare function getName(): string;
}
/** A table of data representing a database query result, which is usually generated by executing a statement that queries the database. */
/**
* A table of data representing a database query result, which is usually generated by executing a statement that queries the database.
* DatabaseResultRow instances are not expected to live once DatabaseResultSet::next has been called on its parent result set.
*/
declare class NJSDatabaseResultRow
{
/**
Expand Down Expand Up @@ -1178,7 +1181,10 @@ declare class NJSDatabaseResultRow
*/
declare function getBlobByPos(pos: number): NJSDatabaseBlob;
}
/** ResultSet is a cursor over a query result. It allows user to iterate through query rows. */
/**
* ResultSet is a cursor over a query result. It allows user to iterate through query rows. When you start iterating through
* result the cursor is placed before the first element of the set.
*/
declare class NJSDatabaseResultSet
{
/**
Expand All @@ -1188,26 +1194,21 @@ declare class NJSDatabaseResultSet
declare function getRow(): NJSDatabaseResultRow;
/** Get the number of rows updated by the query (UPDATE, INSERT, DELETE...) */
declare function getUpdateCount(): number;
/**
* Get the number of row retrieved
* @return The number of rows retrieved by the query
*/
declare function getRowNumber(): number;
/**
* Returns the number of remaining rows to get before the end of the result set.
* @return The number of rows remaining rows to get before the end of the result set.
*/
declare function available(): number;
/**
* Returns true if the result set has at least one remaining row to get.
* @return true if the result set has at least one remaining row to get, false otherwise.
*/
declare function hasNext(): boolean;
/**
* Move the result set to the next available result. This method may fail if there is now further row to fetch.
* Returns the number of remaining rows before the result set needs to load more rows
* @return The number of remaining rows before the result set needs to load more rows.
*/
declare function available(): number;
/**
* Internally move the result set to the next available row. This method may fail if there is no further row to fetch.
* @return Return a result set pointing to the next row.
*/
declare function next(): NJSDatabaseResultSet;
declare function next();
/** Close the result set. */
declare function close();
/** Get the last error that occured on the database. */
Expand Down Expand Up @@ -2261,6 +2262,16 @@ declare class NJSWalletPool
* The return value is always true and doesn’t convey any useful information for now.
*/
declare function freshResetAll(callback: NJSErrorCodeCallback);
/**
* Change Database password.
*
* Allow to change password of database holding all informations about
* accounts, wallets, transactions ...
*
* WARNING: be carefull to have no other instances of WalletPool using
* same database
*/
declare function changePassword(oldPassword: string, newPassword: string, callback: NJSErrorCodeCallback);
}
/** Callback triggered by main completed task, returning optional result as list of template type T. */
declare class NJSWalletListCallback
Expand Down

0 comments on commit 9c21ab4

Please sign in to comment.