Skip to content

Commit

Permalink
Merge pull request #1 from bitshares/develop
Browse files Browse the repository at this point in the history
Merge upstream/develop
  • Loading branch information
btcinshares authored Nov 23, 2017
2 parents e8da8e0 + 7272b69 commit 6d2dadc
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 53 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ RUN \
cmake \
git \
libbz2-dev \
libreadline6-dev \
libreadline-dev \
libboost-all-dev \
libcurl4-openssl-dev \
libssl-dev \
libncurses-dev \
doxygen \
libcurl4-openssl-dev \
&& \
apt-get update -y && \
apt-get install -y fish && \
Expand Down
96 changes: 73 additions & 23 deletions docker/bitsharesentry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,82 @@ BITSHARESD="/usr/local/bin/witness_node"
# For blockchain download
VERSION=`cat /etc/bitshares/version`

## seed nodes come from doc/seednodes.txt which is
## installed by docker into /etc/bitsharesd/seednodes.txt
# SEED_NODES="$(cat /etc/bitsharesd/seednodes.txt | awk -F' ' '{print $1}')"

## if user did not pass in any desired
## seed nodes, use the ones above:
#if [[ -z "$BITSHARESD_SEED_NODES" ]]; then
# for NODE in $SEED_NODES ; do
# ARGS+=" --seed-node=$NODE"
# done
#fi
## Supported Environmental Variables
#
# * $BITSHARESD_SEED_NODES
# * $BITSHARESD_RPC_ENDPOINT
# * $BITSHARESD_PLUGINS
# * $BITSHARESD_REPLAY
# * $BITSHARESD_RESYNC
# * $BITSHARESD_P2P_ENDPOINT
# * $BITSHARESD_WITNESS_ID
# * $BITSHARESD_PRIVATE_KEY
# * $BITSHARESD_TRACK_ACCOUNTS
# * $BITSHARESD_PARTIAL_OPERATIONS
# * $BITSHARESD_MAX_OPS_PER_ACCOUNT
# * $BITSHARESD_ES_NODE_URL
# * $BITSHARESD_TRUSTED_NODE
#

## Link the bitshares config file into home
## This link has been created in Dockerfile, already
ln -f -s /etc/bitshares/config.ini /var/lib/bitshares
ARGS=""
# Translate environmental variables
if [[ ! -z "$BITSHARESD_SEED_NODES" ]]; then
for NODE in $BITSHARESD_SEED_NODES ; do
ARGS+=" --seed-node=$NODE"
done
fi
if [[ ! -z "$BITSHARESD_RPC_ENDPOINT" ]]; then
ARGS+=" --rpc-endpoint=${BITSHARESD_RPC_ENDPOINT}"
fi

if [[ ! -z "$BITSHARESD_PLUGINS" ]]; then
ARGS+=" --plugins=\"${BITSHARESD_PLUGINS}\""
fi

if [[ ! -z "$BITSHARESD_REPLAY" ]]; then
ARGS+=" --replay-blockchain"
fi

if [[ ! -z "$BITSHARESD_RESYNC" ]]; then
ARGS+=" --resync-blockchain"
fi

if [[ ! -z "$BITSHARESD_P2P_ENDPOINT" ]]; then
ARGS+=" --p2p-endpoint=${BITSHARESD_P2P_ENDPOINT}"
fi

if [[ ! -z "$BITSHARESD_WITNESS_ID" ]]; then
ARGS+=" --witness-id=$BITSHARESD_WITNESS_ID"
fi

## get blockchain state from an S3 bucket
# echo bitsharesd: beginning download and decompress of s3://$S3_BUCKET/blockchain-$VERSION-latest.tar.bz2
if [[ ! -z "$BITSHARESD_PRIVATE_KEY" ]]; then
ARGS+=" --private-key=$BITSHARESD_PRIVATE_KEY"
fi

## get blockchain state from an S3 bucket
#s3cmd get s3://$S3_BUCKET/blockchain-$VERSION-latest.tar.bz2 - | pbzip2 -m2000dc | tar x
#if [[ $? -ne 0 ]]; then
# echo unable to pull blockchain state from S3 - exiting
# exit 1
#fi
if [[ ! -z "$BITSHARESD_TRACK_ACCOUNTS" ]]; then
for ACCOUNT in $BITSHARESD_TRACK_ACCOUNTS ; do
ARGS+=" --track-account=$ACCOUNT"
done
fi

## Deploy Healthcheck daemon
if [[ ! -z "$BITSHARESD_PARTIAL_OPERATIONS" ]]; then
ARGS+=" --partial-operations=${BITSHARESD_PARTIAL_OPERATIONS}"
fi

if [[ ! -z "$BITSHARESD_MAX_OPS_PER_ACCOUNT" ]]; then
ARGS+=" --max-ops-per-account=${BITSHARESD_MAX_OPS_PER_ACCOUNT}"
fi

if [[ ! -z "$BITSHARESD_ES_NODE_URL" ]]; then
ARGS+=" --elasticsearch-node-url=${BITSHARESD_ES_NODE_URL}"
fi

if [[ ! -z "$BITSHARESD_TRUSTED_NODE" ]]; then
ARGS+=" --trusted-node=${BITSHARESD_TRUSTED_NODE}"
fi

## Link the bitshares config file into home
## This link has been created in Dockerfile, already
ln -f -s /etc/bitshares/config.ini /var/lib/bitshares

$BITSHARESD --data-dir ${HOME} ${ARGS} ${BITSHARESD_ARGS}
12 changes: 12 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,9 @@ set<public_key_type> database_api_impl::get_potential_signatures( const signed_t
const auto& auth = id(_db).active;
for( const auto& k : auth.get_keys() )
result.insert(k);
// Also insert owner keys since owner can authorize a trx that requires active only
for( const auto& k : id(_db).owner.get_keys() )
result.insert(k);
return &auth;
},
[&]( account_id_type id )
Expand All @@ -1867,6 +1870,15 @@ set<public_key_type> database_api_impl::get_potential_signatures( const signed_t
_db.get_global_properties().parameters.max_authority_depth
);

// Insert keys in required "other" authories
flat_set<account_id_type> required_active;
flat_set<account_id_type> required_owner;
vector<authority> other;
trx.get_required_authorities( required_active, required_owner, other );
for( const auto& auth : other )
for( const auto& key : auth.get_keys() )
result.insert( key );

wdump((result));
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3928,6 +3928,9 @@ blind_confirmation wallet_api::transfer_from_blind( string from_blind_account_ke
ilog( "about to validate" );
conf.trx.validate();

ilog( "about to broadcast" );
conf.trx = sign_transaction( conf.trx, broadcast );

if( broadcast && conf.outputs.size() == 2 ) {

// Save the change
Expand All @@ -3945,9 +3948,6 @@ blind_confirmation wallet_api::transfer_from_blind( string from_blind_account_ke
//} catch ( ... ){}
}

ilog( "about to broadcast" );
conf.trx = sign_transaction( conf.trx, broadcast );

return conf;
} FC_CAPTURE_AND_RETHROW( (from_blind_account_key_or_label)(to_account_id_or_name)(amount_in)(symbol) ) }

Expand Down Expand Up @@ -4020,7 +4020,7 @@ blind_confirmation wallet_api::blind_transfer_help( string from_key_or_label,
my->_wallet.blind_receipts.modify( itr, []( blind_receipt& r ){ r.used = true; } );
}

FC_ASSERT( total_amount >= amount+blind_tr.fee, "Insufficent Balance", ("available",total_amount)("amount",amount)("fee",blind_tr.fee) );
FC_ASSERT( total_amount >= amount+blind_tr.fee, "Insufficient Balance", ("available",total_amount)("amount",amount)("fee",blind_tr.fee) );

auto one_time_key = fc::ecc::private_key::generate();
auto secret = one_time_key.get_shared_secret( to_key );
Expand Down
106 changes: 81 additions & 25 deletions tests/tests/database_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,102 @@

#include <graphene/app/database_api.hpp>

#include <fc/crypto/digest.hpp>

#include "../common/database_fixture.hpp"

using namespace graphene::chain;
using namespace graphene::chain::test;

BOOST_FIXTURE_TEST_SUITE(database_api_tests, database_fixture)

BOOST_AUTO_TEST_CASE(is_registered) {
BOOST_AUTO_TEST_CASE(is_registered) {
try {
/***
* Arrange
*/
auto nathan_private_key = generate_private_key("nathan");
public_key_type nathan_public = nathan_private_key.get_public_key();

auto dan_private_key = generate_private_key("dan");
public_key_type dan_public = dan_private_key.get_public_key();

auto unregistered_private_key = generate_private_key("unregistered");
public_key_type unregistered_public = unregistered_private_key.get_public_key();


/***
* Act
*/
create_account("dan", dan_private_key.get_public_key()).id;
create_account("nathan", nathan_private_key.get_public_key()).id;
// Unregistered key will not be registered with any account


/***
* Assert
*/
graphene::app::database_api db_api(db);

BOOST_CHECK(db_api.is_public_key_registered((string) nathan_public));
BOOST_CHECK(db_api.is_public_key_registered((string) dan_public));
BOOST_CHECK(!db_api.is_public_key_registered((string) unregistered_public));

} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( get_potential_signatures_owner_and_active ) {
try {
fc::ecc::private_key nathan_key1 = fc::ecc::private_key::regenerate(fc::digest("key1"));
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
public_key_type pub_key1( nathan_key1.get_public_key() );
public_key_type pub_key2( nathan_key2.get_public_key() );
const account_object& nathan = create_account("nathan", nathan_key1.get_public_key() );

try {
/***
* Arrange
*/
auto nathan_private_key = generate_private_key("nathan");
public_key_type nathan_public = nathan_private_key.get_public_key();
account_update_operation op;
op.account = nathan.id;
op.active = authority(1, pub_key1, 1);
op.owner = authority(1, pub_key2, 1);
trx.operations.push_back(op);
sign(trx, nathan_key1);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.operations.clear();
trx.signatures.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))

transfer_operation op;
op.from = nathan.id;
op.to = account_id_type();
trx.operations.push_back(op);

graphene::app::database_api db_api(db);
set<public_key_type> pub_keys = db_api.get_potential_signatures( trx );

auto dan_private_key = generate_private_key("dan");
public_key_type dan_public = dan_private_key.get_public_key();
BOOST_CHECK( pub_keys.find( pub_key1 ) != pub_keys.end() );
BOOST_CHECK( pub_keys.find( pub_key2 ) != pub_keys.end() );

auto unregistered_private_key = generate_private_key("unregistered");
public_key_type unregistered_public = unregistered_private_key.get_public_key();
} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( get_potential_signatures_other ) {
try {
fc::ecc::private_key priv_key1 = fc::ecc::private_key::regenerate(fc::digest("key1"));
public_key_type pub_key1( priv_key1.get_public_key() );

/***
* Act
*/
create_account("dan", dan_private_key.get_public_key()).id;
create_account("nathan", nathan_private_key.get_public_key()).id;
// Unregistered key will not be registered with any account
const account_object& nathan = create_account( "nathan" );

balance_claim_operation op;
op.deposit_to_account = nathan.id;
op.balance_owner_key = pub_key1;
trx.operations.push_back(op);

/***
* Assert
*/
graphene::app::database_api db_api(db);
graphene::app::database_api db_api(db);
set<public_key_type> pub_keys = db_api.get_potential_signatures( trx );

BOOST_CHECK(db_api.is_public_key_registered((string) nathan_public));
BOOST_CHECK(db_api.is_public_key_registered((string) dan_public));
BOOST_CHECK(!db_api.is_public_key_registered((string) unregistered_public));
BOOST_CHECK( pub_keys.find( pub_key1 ) != pub_keys.end() );

} FC_LOG_AND_RETHROW()
}
} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 6d2dadc

Please sign in to comment.