forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-cli/txid-of: simple helper to get txid.
Signed-off-by: Rusty Russell <[email protected]>
- Loading branch information
1 parent
114161a
commit ee3af28
Showing
5 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |