Updating style.
This commit is contained in:
parent
83fba3de25
commit
1e21eb034b
@ -66,30 +66,28 @@ export abstract class Signer {
|
|||||||
///////////////////
|
///////////////////
|
||||||
// Sub-classes MAY override these
|
// Sub-classes MAY override these
|
||||||
|
|
||||||
getBalance(blockTag?: BlockTag): Promise<BigNumber> {
|
async getBalance(blockTag?: BlockTag): Promise<BigNumber> {
|
||||||
this._checkProvider("getBalance");
|
this._checkProvider("getBalance");
|
||||||
return this.provider.getBalance(this.getAddress(), blockTag);
|
return await this.provider.getBalance(this.getAddress(), blockTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransactionCount(blockTag?: BlockTag): Promise<number> {
|
async getTransactionCount(blockTag?: BlockTag): Promise<number> {
|
||||||
this._checkProvider("getTransactionCount");
|
this._checkProvider("getTransactionCount");
|
||||||
return this.provider.getTransactionCount(this.getAddress(), blockTag);
|
return await this.provider.getTransactionCount(this.getAddress(), blockTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populates "from" if unspecified, and estimates the gas for the transation
|
// Populates "from" if unspecified, and estimates the gas for the transation
|
||||||
estimateGas(transaction: TransactionRequest): Promise<BigNumber> {
|
async estimateGas(transaction: TransactionRequest): Promise<BigNumber> {
|
||||||
this._checkProvider("estimateGas");
|
this._checkProvider("estimateGas");
|
||||||
return resolveProperties(this.checkTransaction(transaction)).then((tx) => {
|
const tx = await resolveProperties(this.checkTransaction(transaction));
|
||||||
return this.provider.estimateGas(tx);
|
return await this.provider.estimateGas(tx);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populates "from" if unspecified, and calls with the transation
|
// Populates "from" if unspecified, and calls with the transation
|
||||||
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string> {
|
async call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string> {
|
||||||
this._checkProvider("call");
|
this._checkProvider("call");
|
||||||
return resolveProperties(this.checkTransaction(transaction)).then((tx) => {
|
const tx = await resolveProperties(this.checkTransaction(transaction));
|
||||||
return this.provider.call(tx, blockTag);
|
return await this.provider.call(tx, blockTag);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populates all fields in a transaction, signs it and sends it to the network
|
// Populates all fields in a transaction, signs it and sends it to the network
|
||||||
@ -102,19 +100,20 @@ export abstract class Signer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getChainId(): Promise<number> {
|
async getChainId(): Promise<number> {
|
||||||
this._checkProvider("getChainId");
|
this._checkProvider("getChainId");
|
||||||
return this.provider.getNetwork().then((network) => network.chainId);
|
const network = await this.provider.getNetwork();
|
||||||
|
return network.chainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
getGasPrice(): Promise<BigNumber> {
|
async getGasPrice(): Promise<BigNumber> {
|
||||||
this._checkProvider("getGasPrice");
|
this._checkProvider("getGasPrice");
|
||||||
return this.provider.getGasPrice();
|
return await this.provider.getGasPrice();
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveName(name: string): Promise<string> {
|
async resolveName(name: string): Promise<string> {
|
||||||
this._checkProvider("resolveName");
|
this._checkProvider("resolveName");
|
||||||
return this.provider.resolveName(name);
|
return await this.provider.resolveName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -161,6 +160,7 @@ export abstract class Signer {
|
|||||||
// By default called from: (overriding these prevents it)
|
// By default called from: (overriding these prevents it)
|
||||||
// - sendTransaction
|
// - sendTransaction
|
||||||
async populateTransaction(transaction: TransactionRequest): Promise<TransactionRequest> {
|
async populateTransaction(transaction: TransactionRequest): Promise<TransactionRequest> {
|
||||||
|
|
||||||
const tx: TransactionRequest = await resolveProperties(this.checkTransaction(transaction))
|
const tx: TransactionRequest = await resolveProperties(this.checkTransaction(transaction))
|
||||||
|
|
||||||
if (tx.to != null) { tx.to = Promise.resolve(tx.to).then((to) => this.resolveName(to)); }
|
if (tx.to != null) { tx.to = Promise.resolve(tx.to).then((to) => this.resolveName(to)); }
|
||||||
|
@ -31,27 +31,19 @@ export type Resolvable<T> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Result = { key: string, value: any};
|
type Result = { key: string, value: any};
|
||||||
export function resolveProperties<T>(object: Resolvable<T>): Promise<Similar<T>> {
|
|
||||||
|
|
||||||
|
export async function resolveProperties<T>(object: Readonly<Resolvable<T>>): Promise<Similar<T>> {
|
||||||
const promises: Array<Promise<Result>> = Object.keys(object).map((key) => {
|
const promises: Array<Promise<Result>> = Object.keys(object).map((key) => {
|
||||||
const value = (<any>object)[key];
|
const value = object[<keyof Resolvable<T>>key];
|
||||||
|
return Promise.resolve(value).then((v) => ({ key: key, value: v }));
|
||||||
if (!(value instanceof Promise)) {
|
|
||||||
return Promise.resolve({ key: key, value: value });
|
|
||||||
}
|
|
||||||
|
|
||||||
return value.then((value) => {
|
|
||||||
return { key: key, value: value };
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(promises).then((results) => {
|
const results = await Promise.all(promises);
|
||||||
const result: any = { };
|
|
||||||
return (<Similar<T>>(results.reduce((accum, result) => {
|
return results.reduce((accum, result) => {
|
||||||
accum[result.key] = result.value;
|
accum[<keyof Similar<T>>(result.key)] = result.value;
|
||||||
return accum;
|
return accum;
|
||||||
}, result)));
|
}, <Similar<T>>{ });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void {
|
export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void {
|
||||||
|
@ -387,7 +387,7 @@ export class FallbackProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// They were all an error; pick the first error
|
// They were all an error; pick the first error
|
||||||
return Promise.reject(results[0].error);
|
return Promise.reject(results[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user