Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest: added utxo confirmations #236

Open
wants to merge 2 commits into
base: 0.1.4-dogebox-pre
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
goal: install
- name: x86_64-macos
host: x86_64-apple-darwin15
os: macos-12
os: macos-13
run-tests: true
dep-opts: "SPEED=slow V=1"
config-opts: "--enable-static --disable-shared --enable-test-passwd"
Expand Down
2 changes: 1 addition & 1 deletion include/dogecoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern const dogecoin_chainparams dogecoin_chainparams_test;
extern const dogecoin_chainparams dogecoin_chainparams_regtest;

// the mainnet checkpoints, needs a fix size
extern const dogecoin_checkpoint dogecoin_mainnet_checkpoint_array[23];
extern const dogecoin_checkpoint dogecoin_mainnet_checkpoint_array[24];
extern const dogecoin_checkpoint dogecoin_testnet_checkpoint_array[19];

LIBDOGECOIN_API const dogecoin_chainparams* chain_from_b58_prefix(const char* address);
Expand Down
2 changes: 2 additions & 0 deletions include/dogecoin/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct dogecoin_utxo_ {
char script_pubkey[SCRIPT_PUBKEY_STRINGLEN];
char amount[KOINU_STRINGLEN];
int confirmations;
int height;
dogecoin_bool spendable;
dogecoin_bool solvable;
UT_hash_handle hh;
Expand Down Expand Up @@ -125,6 +126,7 @@ LIBDOGECOIN_API void remove_dogecoin_utxo(dogecoin_utxo* utxo);
LIBDOGECOIN_API void remove_all_utxos();
LIBDOGECOIN_API void dogecoin_wallet_utxo_free(dogecoin_utxo* utxo);
LIBDOGECOIN_API void dogecoin_wallet_scrape_utxos(dogecoin_wallet* wallet, dogecoin_wtx* wtx);
LIBDOGECOIN_API void dogecoin_wallet_utxos_update_confirmations(int height);
/** ------------------------------------ */

/** wallet addr functions */
Expand Down
3 changes: 2 additions & 1 deletion src/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const dogecoin_checkpoint dogecoin_mainnet_checkpoint_array[] = {
{3854173, "e4b4ecda4c022406c502a247c0525480268ce7abbbef632796e8ca1646425e75", 1628934997, 0x1a03ca36},
{3963597, "2b6927cfaa5e82353d45f02be8aadd3bfd165ece5ce24b9bfa4db20432befb5d", 1635884460, 0x1a037bc9},
{4303965, "ed7d266dcbd8bb8af80f9ccb8deb3e18f9cc3f6972912680feeb37b090f8cee0", 1657646310, 0x1a0344f5},
{5050000, "e7d4577405223918491477db725a393bcfc349d8ee63b0a4fde23cbfbfd81dea", 1705383360, 0x1a019541}};
{5050000, "e7d4577405223918491477db725a393bcfc349d8ee63b0a4fde23cbfbfd81dea", 1705383360, 0x1a019541},
{5400000, "cbb1f4ae807da83e13bdf9c28188982938c9ee6bf560c1023f51adac229eef87", 1727704957, 0x0106DAC9}};

const dogecoin_checkpoint dogecoin_testnet_checkpoint_array[] = {
{0, "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e", 1391503289, 0x1e0ffff0},
Expand Down
1 change: 1 addition & 0 deletions src/rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void dogecoin_http_request_cb(struct evhttp_request *req, void *arg) {
evbuffer_add_printf(evb, "address: %s\n", utxo->address);
evbuffer_add_printf(evb, "script_pubkey: %s\n", utxo->script_pubkey);
evbuffer_add_printf(evb, "amount: %s\n", utxo->amount);
evbuffer_add_printf(evb, "confirmations: %d\n", utxo->confirmations);
evbuffer_add_printf(evb, "spendable: %d\n", utxo->spendable);
evbuffer_add_printf(evb, "solvable: %d\n", utxo->solvable);
wallet_total_u64_unspent += coins_to_koinu_str(utxo->amount);
Expand Down
15 changes: 13 additions & 2 deletions src/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ void dogecoin_wallet_scrape_utxos(dogecoin_wallet* wallet, dogecoin_wtx* wtx) {
memcpy_safe(utxo->address, p2pkh_from_script_pubkey, P2PKHLEN);
// set amount of utxo:
koinu_to_coins_str(tx_out->value, utxo->amount);
// set the height of the utxo:
utxo->height = wtx->height;
// finally add utxo to rbtree:
dogecoin_btree_tfind(utxo, &wallet->unspent_rbtree, dogecoin_utxo_compare);
add_dogecoin_utxo(utxo);
Expand All @@ -749,8 +751,18 @@ void dogecoin_wallet_scrape_utxos(dogecoin_wallet* wallet, dogecoin_wtx* wtx) {
vector_free(addrs, true);
}
}

// update the wallet with the new utxos:
wallet->utxos = utxos;
}

void dogecoin_wallet_utxos_update_confirmations(int height) {
dogecoin_utxo* utxo;
dogecoin_utxo* tmp;
HASH_ITER(hh, utxos, utxo, tmp) {
utxo->confirmations = height - utxo->height + 1;
}
}
void dogecoin_wallet_add_wtx_intern_move(dogecoin_wallet *wallet, const dogecoin_wtx *wtx) {
// check if wtx already exists
dogecoin_wtx* checkwtx = dogecoin_btree_tfind(wtx, &wallet->wtxes_rbtree, dogecoin_wtx_compare);
Expand Down Expand Up @@ -992,8 +1004,6 @@ dogecoin_bool dogecoin_wallet_load(dogecoin_wallet* wallet, const char* file_pat
}
}

wallet->utxos = utxos;

return true;
}

Expand Down Expand Up @@ -1519,6 +1529,7 @@ void dogecoin_wallet_check_transaction(void *ctx, dogecoin_tx *tx, unsigned int
dogecoin_wallet_scrape_utxos(wallet, wtx);
dogecoin_wallet_add_wtx_move(wallet, wtx);
}
dogecoin_wallet_utxos_update_confirmations(pindex->height);
}

dogecoin_wallet* dogecoin_wallet_read(char* address) {
Expand Down
Loading