Skip to content

Commit

Permalink
Address comments: renaming to WalletAddress, added test case fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cb committed Jun 20, 2024
1 parent 3af3c22 commit 8b0567b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { delay } from "../utils";
import { Wallet as WalletClass } from "../wallet";

/**
* A representation of a blockchain address, which is a developer-controlled account on a network.
* A representation of a blockchain address, which is a wallet-controlled account on a network.
*/
export class DeveloperAddress extends Address {
export class WalletAddress extends Address {
private _model: AddressModel;
private _key?: ethers.SigningKey;

/**
* Initializes a new Developer Address instance.
* Initializes a new Wallet Address instance.
*
* @param model - The address model data.
* @param key - The ethers.js SigningKey the Address uses to sign data.
Expand All @@ -39,12 +39,12 @@ export class DeveloperAddress extends Address {
}

/**
* Returns a string representation of the developer address.
* Returns a string representation of the wallet address.
*
* @returns {string} A string representing the developer address.
* @returns {string} A string representing the wallet address.
*/
public toString(): string {
return `Coinbase:DeveloperAddress{addressId: '${this.getId()}', networkId: '${this.getNetworkId()}', walletId: '${this.getWalletId()}'}`;
return `Coinbase:WalletAddress{addressId: '${this.getId()}', networkId: '${this.getNetworkId()}', walletId: '${this.getWalletId()}'}`;
}

/**
Expand All @@ -62,7 +62,7 @@ export class DeveloperAddress extends Address {
* @param key - The ethers.js SigningKey the Address uses to sign data.
* @throws {InternalError} If the private key is already set.
*/
public getKey(key: ethers.SigningKey) {
public setKey(key: ethers.SigningKey) {
if (this._key !== undefined) {
throw new InternalError("Private key is already set");
}
Expand Down Expand Up @@ -258,7 +258,7 @@ export class DeveloperAddress extends Address {
* @returns Whether the Address has a private key backing it to sign transactions.
*/
public canSign(): boolean {
return !!this.getKey;
return !!this._key;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { BalanceMap } from "./balance_map";
import Decimal from "decimal.js";
import { Balance } from "./balance";
import { Trade } from "./trade";
import { DeveloperAddress } from "./address/developer_address";
import { WalletAddress } from "./address/wallet_address";
import { Asset } from "./asset";

/**
Expand All @@ -36,7 +36,7 @@ export class Wallet {

private master?: HDKey;
private seed?: string;
private addresses: DeveloperAddress[] = [];
private addresses: WalletAddress[] = [];
private addressModels: AddressModel[] = [];

private readonly addressPathPrefix = "m/44'/60'/0'/0";
Expand Down Expand Up @@ -213,7 +213,7 @@ export class Wallet {
const response = await Coinbase.apiClients.address!.createAddress(this.model.id!, payload);

this.cacheAddress(response!.data, key);
return new DeveloperAddress(response!.data, key);
return new WalletAddress(response!.data, key);
}

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ export class Wallet {
* @returns {void}
*/
private cacheAddress(address: AddressModel, key?: ethers.Wallet): void {
this.addresses.push(new DeveloperAddress(address, key?.signingKey));
this.addresses.push(new WalletAddress(address, key?.signingKey));
}

/**
Expand Down Expand Up @@ -547,7 +547,7 @@ export class Wallet {
*
* @returns The default address
*/
public getDefaultAddress(): DeveloperAddress | undefined {
public getDefaultAddress(): WalletAddress | undefined {
return this.addresses.find(
address => address.getId() === this.model.default_address?.address_id,
);
Expand Down
Loading

0 comments on commit 8b0567b

Please sign in to comment.