Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update address to follow specs #552

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/abi/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("test smart contract interactor", function () {
const hexBar = "4241522d356263303866";
const hexLKMEX = "4c4b4d45582d616162393130";
const hexNFT = "4d4f532d623962346232";
const hexContractAddress = new Address(contract.getAddress().toBech32()).toHex();
const hexContractAddress = contract.getAddress().toHex();
const hexDummyFunction = "64756d6d79";

// ESDT, single
Expand Down
3 changes: 1 addition & 2 deletions src/abi/smartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ export class SmartContract implements ISmartContract {
* @param nonce The owner nonce used for the deployment transaction
*/
static computeAddress(owner: Address, nonce: bigint): Address {
const deployer = Address.newFromBech32(owner.toBech32());
const addressComputer = new AddressComputer();
return addressComputer.computeContractAddress(deployer, BigInt(nonce.valueOf()));
return addressComputer.computeContractAddress(owner, BigInt(nonce.valueOf()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nonce is already of type bigint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be chaged in a future PR.

}
}
2 changes: 1 addition & 1 deletion src/accountManagement/accountTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AccountTransactionsFactory {
createTransactionForSettingGuardian(sender: Address, options: SetGuardianInput): Transaction {
const dataParts = [
"SetGuardian",
Address.newFromBech32(options.guardianAddress.toBech32()).toHex(),
options.guardianAddress.toHex(),
Buffer.from(options.serviceID).toString("hex"),
];

Expand Down
5 changes: 2 additions & 3 deletions src/entrypoints/entrypoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ describe("TestEntrypoint", () => {
this.timeout(30000);
const abi = await loadAbiRegistry("src/testdata/adder.abi.json");
const sender = Account.newFromPem(alicePem.pemFileText);
const accountAddress = new Address(sender.address);
sender.nonce = await entrypoint.recallAccountNonce(accountAddress);
sender.nonce = await entrypoint.recallAccountNonce(sender.address);

const controller = entrypoint.createSmartContractController(abi);
const bytecode = readFileSync("src/testdata/adder.wasm");
Expand All @@ -63,7 +62,7 @@ describe("TestEntrypoint", () => {

assert.equal(outcome.contracts.length, 1);

const contractAddress = Address.fromBech32(outcome.contracts[0].address);
const contractAddress = Address.newFromBech32(outcome.contracts[0].address);

const executeTransaction = await controller.createTransactionForExecute(
sender,
Expand Down
2 changes: 1 addition & 1 deletion src/smartContracts/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class SmartContractTransactionsFactory {
contract: Address;
newOwner: Address;
}): Transaction {
const dataParts = ["ChangeOwnerAddress", Address.newFromBech32(options.newOwner.toBech32()).toHex()];
const dataParts = ["ChangeOwnerAddress", options.newOwner.toHex()];

return new TransactionBuilder({
config: this.config,
Expand Down
2 changes: 1 addition & 1 deletion src/tokenOperations/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function bigIntToBuffer(value: BigNumber.Value): Buffer {
return contractsCodecUtils.bigIntToBuffer(value);
}

export { addressToHex, bigIntToHex, utf8ToHex } from "../utils.codec";
export { bigIntToHex, utf8ToHex } from "../utils.codec";

export function bufferToHex(value: Buffer) {
const hex = value.toString("hex");
Expand Down
6 changes: 0 additions & 6 deletions src/utils.codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BigNumber from "bignumber.js";
import * as contractsCodecUtils from "./abi/codec/utils";
import { Address } from "./address";

export function numberToPaddedHex(value: bigint | number | BigNumber.Value) {
let hexableNumber: { toString(radix?: number): string };
Expand Down Expand Up @@ -52,8 +51,3 @@ export function bigIntToHex(value: BigNumber.Value): string {

return contractsCodecUtils.getHexMagnitudeOfBigInt(value);
}

export function addressToHex(address: Address): string {
const buffer = Address.newFromBech32(address.toString()).getPublicKey();
return buffer.toString("hex");
}
Loading