feat: customizable syncState method

This commit is contained in:
asiaziola
2022-07-18 12:21:52 +02:00
parent fa99c2919a
commit 9d6fd2cc48
3 changed files with 23 additions and 20 deletions

View File

@@ -735,9 +735,14 @@ export class HandlerBasedContract<State> implements Contract<State> {
return hash.digest('hex');
}
async syncState(nodeAddress: string): Promise<Contract> {
async syncState(externalUrl: string, params?: object): Promise<Contract> {
const { stateEvaluator } = this.warp;
const response = await fetch(`${nodeAddress}/state?id=${this._contractTxId}&validity=true&safeHeight=true`)
const response = await fetch(
`${externalUrl}?${new URLSearchParams({
id: this._contractTxId,
...params
})}`
)
.then((res) => {
return res.ok ? res.json() : Promise.reject(res);
})