signTransaction returns TransactionBuilder
This commit is contained in:
@@ -68,7 +68,7 @@ export class Address {
|
||||
): Address {
|
||||
// Attempt to decode as a Cash Address.
|
||||
try {
|
||||
return this.fromCashAddr(address, tryPrefixes);
|
||||
return this.fromCashAddr(address, false, tryPrefixes);
|
||||
} catch (_error) {
|
||||
// And if that fails, attempt to decode as a Base58 Address.
|
||||
return this.fromLegacy(address);
|
||||
@@ -89,6 +89,7 @@ export class Address {
|
||||
*/
|
||||
public static fromCashAddr(
|
||||
cashAddr: string,
|
||||
requireTokenSupport = false,
|
||||
tryPrefixes: Array<string> = DEFAULT_ADDRESS_PREFIXES,
|
||||
): Address {
|
||||
// Try all prefixes (including empty string) until we find a valid decode
|
||||
@@ -105,6 +106,16 @@ export class Address {
|
||||
// Define the encode type in advance.
|
||||
let encodeType: AddressType;
|
||||
|
||||
// Determine whether this is a CashToken address.
|
||||
const isTokenAddress =
|
||||
decodeResult.type === 'p2pkhWithTokens' ||
|
||||
decodeResult.type === 'p2shWithTokens';
|
||||
|
||||
// If this is not a CashToken Address, but we require a CashToken address, throw an error.
|
||||
if (!isTokenAddress && requireTokenSupport) {
|
||||
throw new Error(`Address '${cashAddr}' does not support tokens`);
|
||||
}
|
||||
|
||||
// Determine the encoding to use based on the Decoding Result's Type.
|
||||
switch (decodeResult.type) {
|
||||
case 'p2pkh':
|
||||
@@ -365,7 +376,27 @@ export class Address {
|
||||
tryPrefixes = DEFAULT_ADDRESS_PREFIXES,
|
||||
): boolean {
|
||||
try {
|
||||
Address.fromCashAddr(address, tryPrefixes);
|
||||
Address.fromCashAddr(address, false, tryPrefixes);
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given address is a valid CashAddr with Token Support.
|
||||
*
|
||||
* @param address The address.
|
||||
*
|
||||
* @returns boolean indicating whether the address is a valid CashAddr with Token Support.
|
||||
*/
|
||||
public static isValidTokenAddress(
|
||||
address: string,
|
||||
tryPrefixes = DEFAULT_ADDRESS_PREFIXES,
|
||||
): boolean {
|
||||
try {
|
||||
Address.fromCashAddr(address, true, tryPrefixes);
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user