-
Notifications
You must be signed in to change notification settings - Fork 14
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
Cache contract wrappers #334
Conversation
config/default.json
Outdated
@@ -1,6 +1,7 @@ | |||
{ | |||
"autoApproveTokenTransfers": true, | |||
"defaultVotingMachine": "AbsoluteVote", | |||
"cacheContractWrappers": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not true? seems like a no-brainer to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just being conservative: This feature consumes a technically limitless amount of memory. Maybe you're right though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, only as much memory as there are contracts to cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's why I said "technically"
@@ -8,6 +10,18 @@ import { Web3EventService } from "./web3EventService"; | |||
export class ContractWrapperFactory<TWrapper extends IContractWrapperBase> | |||
implements IContractWrapperFactory<TWrapper> { | |||
|
|||
public static setConfigService(configService: IConfigService): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general would like a description of all the changes that are happening to the config service in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did describe the change in the description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... there is otherwise no change noticible to users of arc.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes, I did make an internal change and could've mentioned that here
@@ -49,9 +88,50 @@ export class ContractWrapperFactory<TWrapper extends IContractWrapperBase> | |||
*/ | |||
public async deployed(): Promise<TWrapper> { | |||
await this.ensureSolidityContract(); | |||
return new this.wrapper(this.solidityContract, this.web3EventService).hydrateFromDeployed(); | |||
|
|||
const getWrapper = (): Promise<TWrapper> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost all this code is a duplicate of .at, any easy way to merge/reuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried that but they are each a bit different. I decided it wasn't worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end it was possible
lib/contractWrapperFactory.ts
Outdated
} | ||
addressMap.set(wrapper.address, wrapper); | ||
if (!at) { | ||
// so we can also get the deployed version of this contract without the address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use the deployed address as the name? otherwise you could have two copies of the same contract in the cache depending on if you call .deployed or .at
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "${name}_deployed" key is for when users call deployed()
, which supplies no address, only the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but the deployed contract has an address, which you could use as the name of the key so that you dont end up with two copies of the same cached contract
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a way to do it
faaf710
to
bedc026
Compare
bedc026
to
f37aed7
Compare
} | ||
|
||
if (address) { | ||
hydratedWrapper = this.getCachedContract(this.solidityContractName, address) as TWrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should maybe log if the returned contract is coming from the cache or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was wanting to do that too. done.
Resolves: #324
Cache contract wrappers obtained using the contract wrapper factory methods
.at
and.new
. The cache is local, it does not persist across application instances.The feature is controlled by the
cacheContractWrappers
config setting which is set totrue
by default.