-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59ec5c3
commit d1283ad
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { BroadcastTransactionMap, TransactionEndpoint, TxFee } from "@gnolang/tm2-js-client"; | ||
import { GnoWallet } from "../wallet"; | ||
import { parseGnoReturns } from "../wallet/helpers"; | ||
|
||
const realm = "/r/demo/boards"; | ||
const realmTS= "r_demo_boards"; | ||
type GetBoardIDFromNameReturn = [number, boolean] | ||
const queryClient = (wallet: GnoWallet) => { | ||
return { | ||
async GetBoardIDFromName(params: { name: string }, height?: number):Promise<GetBoardIDFromNameReturn> { | ||
const result = await wallet.getProvider().evaluateExpression(realm,`GetBoardIDFromName("${name}")`,height); | ||
return parseGnoReturns(result) as GetBoardIDFromNameReturn; | ||
} | ||
} | ||
} | ||
const txClient = (wallet: GnoWallet) => { | ||
return { | ||
async GetBoardIDFromName(params: { name: string }, funds: Map<string,number>, fee: TxFee):Promise<GetBoardIDFromNameReturn> { | ||
|
||
const resp = (await wallet.callMethod( | ||
realm, | ||
"GetBoardIDFromName", | ||
[params.name], | ||
TransactionEndpoint.BROADCAST_TX_COMMIT, | ||
funds, | ||
fee | ||
)); | ||
const result = atob(resp.deliver_tx.ResponseBase.Data as string) | ||
return parseGnoReturns(result) as GetBoardIDFromNameReturn; | ||
}, | ||
} | ||
} | ||
class RealmModule { | ||
public query: ReturnType<typeof queryClient>; | ||
public tx: ReturnType<typeof txClient>; | ||
|
||
constructor(wallet: GnoWallet) { | ||
this.updateQuery(wallet); | ||
this.updateTX(wallet); | ||
} | ||
updateTX(wallet: GnoWallet) { | ||
const methods = txClient(wallet); | ||
|
||
this.tx = methods; | ||
for (let m in methods) { | ||
this.tx[m as keyof typeof methods] = methods[m as keyof typeof methods].bind(this.tx); | ||
} | ||
} | ||
updateQuery(wallet: GnoWallet) { | ||
const methods = queryClient(wallet); | ||
|
||
this.query = methods; | ||
for (let m in methods) { | ||
this.query[m as keyof typeof methods] = methods[m as keyof typeof methods].bind(this.query); | ||
} | ||
} | ||
}; | ||
|
||
const Realm = (wallet: GnoWallet) => { | ||
return { | ||
realm: { | ||
[realmTS]: new RealmModule(wallet) | ||
} | ||
} | ||
} | ||
export default Realm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { GnoWallet } from '../wallet'; | ||
import Realm from './realm-module'; | ||
const RealmWallet = GnoWallet.addRealm(Realm) | ||
const wallet = new RealmWallet(); | ||
|
||
const test = async () => { | ||
const [boardId, exists] = await wallet.r_demo_boards.query.GetBoardIDFromName({ name: "testboard"}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters