MCPcopy Create free account
hub / github.com/ElementsProject/lightning / is_bitcoin_address

Function is_bitcoin_address

common/splice_script.c:927–974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925}
926
927static bool is_bitcoin_address(const char *address)
928{
929 struct ripemd160 addr;
930 int witness_version;
931 /* segwit_addr_net_decode requires a buffer of size 40, and will
932 * not write to the buffer if the address is too long, so a buffer
933 * of fixed size 40 will not overflow. */
934 uint8_t witness_program[40];
935 size_t witness_program_len;
936
937 const char *bech32;
938
939 u8 addr_version;
940
941 if (ripemd160_from_base58(&addr_version, &addr,
942 address, strlen(address))) {
943 if (addr_version == chainparams->p2pkh_version) {
944 return true;
945 } else if (addr_version == chainparams->p2sh_version) {
946 return true;
947 }
948 return false;
949 }
950
951 bech32 = segwit_addr_net_decode(&witness_version, witness_program,
952 &witness_program_len, address,
953 chainparams);
954 if (bech32) {
955 bool witness_ok;
956
957 /* Only V0 has restricted lengths of witness programs */
958 if (witness_version == 0) {
959 witness_ok = (witness_program_len == 20 ||
960 witness_program_len == 32);
961 } else if (witness_version == 1) {
962 witness_ok = (witness_program_len == 32);
963 } else {
964 witness_ok = true;
965 }
966
967 if (!witness_ok)
968 return false;
969
970 return true;
971 }
972
973 return false;
974}
975
976/* Checks token->str for a short node id and auto completes it. */
977static bool autocomplete_node_id(struct token *token,

Callers 1

type_dataFunction · 0.85

Calls 2

ripemd160_from_base58Function · 0.85
segwit_addr_net_decodeFunction · 0.70

Tested by

no test coverage detected