From 0998d805e51fe5811b6d938564d2f1acf8fc3be4 Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Thu, 10 Aug 2023 14:05:02 +0200 Subject: [PATCH] Fix loaded addresses field names --- cmd-rpc-server-car-getTransaction.go | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmd-rpc-server-car-getTransaction.go b/cmd-rpc-server-car-getTransaction.go index 4748a506..09bf3ef0 100644 --- a/cmd-rpc-server-car-getTransaction.go +++ b/cmd-rpc-server-car-getTransaction.go @@ -159,6 +159,39 @@ func adaptTransactionMetaToExpectedOutput(m map[string]any) map[string]any { "writable": []any{}, } } + { + // if has loadedReadonlyAddresses and is []string, then use that for loadedAddresses.readonly + if loadedReadonlyAddresses, ok := meta["loadedReadonlyAddresses"].([]any); ok { + // the address list is base64 encoded; decode and encode to base58 + for i, addr := range loadedReadonlyAddresses { + addrStr, ok := addr.(string) + if ok { + decoded, err := base64.StdEncoding.DecodeString(addrStr) + if err == nil { + loadedReadonlyAddresses[i] = base58.Encode(decoded) + } + } + } + meta["loadedAddresses"].(map[string]any)["readonly"] = loadedReadonlyAddresses + delete(meta, "loadedReadonlyAddresses") + } + // if has loadedWritableAddresses and is []string, then use that for loadedAddresses.writable + if loadedWritableAddresses, ok := meta["loadedWritableAddresses"].([]any); ok { + // the address list is base64 encoded; decode and encode to base58 + for i, addr := range loadedWritableAddresses { + addrStr, ok := addr.(string) + if ok { + decoded, err := base64.StdEncoding.DecodeString(addrStr) + if err == nil { + loadedWritableAddresses[i] = base58.Encode(decoded) + } + } + } + meta["loadedAddresses"].(map[string]any)["writable"] = loadedWritableAddresses + delete(meta, "loadedWritableAddresses") + } + // remove loadedReadonlyAddresses and loadedWritableAddresses + } if _, ok := meta["postTokenBalances"]; !ok { meta["postTokenBalances"] = []any{} }