mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
test-cli/txid-of: simple helper to get txid.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
114161a6a5
commit
ee3af28980
5 changed files with 57 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,6 +21,7 @@ update-channel-accept
|
|||
update-channel-signature
|
||||
update-channel-complete
|
||||
create-commit-tx
|
||||
txid-of
|
||||
ccan/tools/configurator/configurator
|
||||
libsecp256k1.a
|
||||
libsecp256k1.la
|
||||
|
|
2
Makefile
2
Makefile
|
@ -8,7 +8,7 @@ FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1
|
|||
# Bitcoin uses DER for signatures
|
||||
#FEATURES := -DSCRIPTS_USE_DER
|
||||
|
||||
PROGRAMS := test-cli/open-channel test-cli/open-anchor-scriptsigs test-cli/open-commit-sig test-cli/check-commit-sig test-cli/check-anchor-scriptsigs test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx
|
||||
PROGRAMS := test-cli/open-channel test-cli/open-anchor-scriptsigs test-cli/open-commit-sig test-cli/check-commit-sig test-cli/check-anchor-scriptsigs test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx test-cli/txid-of
|
||||
|
||||
BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o
|
||||
|
||||
|
|
|
@ -503,6 +503,14 @@ bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
||||
char *hexstr, size_t hexstr_len)
|
||||
{
|
||||
struct sha256_double rev = *txid;
|
||||
reverse_bytes(rev.sha.u.u8, sizeof(rev.sha.u.u8));
|
||||
return hex_encode(&rev, sizeof(rev), hexstr, hexstr_len);
|
||||
}
|
||||
|
||||
static bool write_input_amounts(int fd, const struct bitcoin_tx *tx)
|
||||
{
|
||||
/* Alpha required input amounts, so append them */
|
||||
|
|
|
@ -64,4 +64,8 @@ bool bitcoin_tx_write(int fd, const struct bitcoin_tx *tx);
|
|||
bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
|
||||
struct sha256_double *txid);
|
||||
|
||||
/* Get hex string of txid (reversed, a-la bitcoind). */
|
||||
bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
||||
char *hexstr, size_t hexstr_len);
|
||||
|
||||
#endif /* LIGHTNING_BITCOIN_TX_H */
|
||||
|
|
43
test-cli/txid-of.c
Normal file
43
test-cli/txid-of.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <ccan/crypto/shachain/shachain.h>
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include "bitcoin/tx.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||
struct bitcoin_tx *tx;
|
||||
struct sha256_double txid;
|
||||
char str[hex_str_size(sizeof(txid))];
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
|
||||
/* FIXME: Take update.pbs to adjust channel */
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<tx>\n"
|
||||
"Print txid of the transaction in the file",
|
||||
"Print this message.");
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
|
||||
if (argc != 2)
|
||||
opt_usage_exit_fail("Expected 1 argument");
|
||||
|
||||
tx = bitcoin_tx_from_file(ctx, argv[1]);
|
||||
bitcoin_txid(tx, &txid);
|
||||
|
||||
if (!bitcoin_txid_to_hex(&txid, str, sizeof(str)))
|
||||
abort();
|
||||
|
||||
/* Print it out. */
|
||||
if (!write_all(STDOUT_FILENO, str, strlen(str)))
|
||||
err(1, "Writing out txid");
|
||||
|
||||
tal_free(ctx);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue