A blind attempt at updating non-familiar languages.
@@ -670,15 +670,14 @@ Anyone may read the [global state](../apps/#reading-global-state-from-other-smar
}
// read global state of application
- async function readGlobalState(client, account, index){
- let accountInfoResponse = await client.accountInformation(account.addr).do();
- for (let i = 0; i < accountInfoResponse['created-apps'].length; i++) {
- if (accountInfoResponse['created-apps'][i].id == index) {
- console.log("Application's global state:");
- for (let n = 0; n < accountInfoResponse['created-apps'][i]['params']['global-state'].length; n++) {
- console.log(accountInfoResponse['created-apps'][i]['params']['global-state'][n]);
- }
+ async function readGlobalState(client, index){
+ let applicationInfoResponse = await client.applicationInfo(index).do();
+ let globalState = []
+ if applicationInfoResponse['params'].includes('global-state') {
+ let globalState = applicationInfoResponse['params']['global-state']
}
+ for (let n = 0; n < applicationInfoResponse['params']['global-state'].length; n++) {
+ console.log(applicationInfoResponse['params']['global-state'][n]);
}
}
```
@@ -696,11 +695,11 @@ Anyone may read the [global state](../apps/#reading-global-state-from-other-smar
}
public void readGlobalState(AlgodClient client, Account account, Long appId) throws Exception {
- Response<com.algorand.algosdk.v2.client.model.Account> acctResponse = client.AccountInformation(account.getAddress()).execute();
- List<Application> createdApplications = acctResponse.body().createdApps;
- for (int i = 0; i < createdApplications.size(); i++) {
- if (createdApplications.get(i).id.equals(appId)) {
- System.out.println("Application global state: " + createdApplications.get(i).params.globalState.toString());
+ Response<com.algorand.algosdk.v2.client.model.Application> appResponse = client.GetApplicationByID(appId).execute();
+ List<TealKeyValue> globalState= appResponse.params.globalState;
+ if !globalState.isEmpty() {
+ for (int i = 0; i < globalState.size(); i++) {
+ System.out.println("Application global state: " + globalState.get(i).toString());
}
}
}
@@ -719,12 +718,10 @@ Anyone may read the [global state](../apps/#reading-global-state-from-other-smar
}
func readGlobalState(client *algod.Client, account crypto.Account, index uint64) {
- accountInfo, _ := client.AccountInformation(account.Address.String()).Do(context.Background())
- for _, ap := range accountInfo.CreatedApps {
- if ap.Id == index {
- fmt.Printf("Global state for app-id %d:\n", ap.Id)
- fmt.Println(ap.Params.GlobalState)
- }
+ applicationInfo, _ := client.GetApplicationByID(index)
+ globalState, _ := applicationInfo.Params.GlobalState
+ if globalState {
+ fmt.Println(globalState)
}
}
```
