Skip to content

Commit f0c9b37

Browse files
added support for custom hrp
1 parent cf6449e commit f0c9b37

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

packages/common/src/sc.interactions/contract.loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class ContractLoader {
2727
}
2828
}
2929

30-
async getContract(contractAddress: string): Promise<SmartContract> {
30+
async getContract(contractAddress: string, hrp?: string): Promise<SmartContract> {
3131
if (!this.abi) {
3232
this.abi = await this.load();
3333
}
3434

3535
return new SmartContract({
36-
address: new Address(contractAddress),
36+
address: new Address(contractAddress, hrp),
3737
abi: this.abi,
3838
});
3939
}

packages/common/src/utils/address.utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { Logger } from "@nestjs/common";
33
import { BinaryUtils } from "./binary.utils";
44

55
export class AddressUtils {
6-
static bech32Encode(publicKey: string) {
7-
return Address.fromHex(publicKey).bech32();
6+
static bech32Encode(publicKey: string, hrp?: string) {
7+
return Address.fromHex(publicKey, hrp).bech32();
88
}
99

1010
static bech32Decode(address: string) {
11-
return Address.fromBech32(address).hex();
11+
return Address.newFromBech32(address).hex();
1212
}
1313

1414
static isAddressValid(address: string): boolean {
1515
try {
16-
Address.fromBech32(address);
16+
Address.newFromBech32(address);
1717
return true;
1818
} catch (error) {
1919
return false;
@@ -55,7 +55,7 @@ export class AddressUtils {
5555
return shard;
5656
}
5757

58-
static isSmartContractAddress(address: string): boolean {
58+
static isSmartContractAddress(address: string, hrp?: string): boolean {
5959
if (address.toLowerCase() === 'metachain') {
6060
return true;
6161
}
@@ -65,7 +65,7 @@ export class AddressUtils {
6565
}
6666

6767
try {
68-
return new Address(address).isContractAddress();
68+
return new Address(address, hrp).isContractAddress();
6969
} catch (error) {
7070
const logger = new Logger(AddressUtils.name);
7171
logger.error(`Error when determining whether address '${address}' is a smart contract address`);

0 commit comments

Comments
 (0)