Fetching block from Cosmos/Osmosis blockchain. Convert bytes to string then decrypt string - encryption

I am trying to fetch data like block_hash from Osmosis chain. The problem is I am getting a Uint8Array that I cannot actually convert to readable string/hash.
Response I get from my js app:
blockId: {
hash: Uint8Array(32) [
91, 215, 254, 180, 87, 180, 160, 121,
12, 47, 235, 35, 219, 203, 27, 45,
102, 213, 50, 40, 54, 194, 33, 28,
231, 139, 216, 246, 45, 73, 58, 188
],
partSetHeader: { total: 2, hash: [Uint8Array] }
}
Response I get from Postman:
"block_id": {
"hash": "mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394=",
"part_set_header": {
"total": 2,
"hash": "u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY="
}
}
First I can't convert the Uint8Array to anything readable because when I try it with this code:
const string = new TextDecoder().decode(hash);
console.log(string);
I get this:
ڨ9�$Օka�
�Ց���ewf�§�qA�♥߂��
Also mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394= is definitely not a valid blockchain transaction hash
A valid one looks like this:
BE2E8DFB4489D0349C78BC30D14802DE88FDF581F8DB6B6FAFA9EB6157646C07
Do you have any ideas is this any kind of encryption and if so how can I decrypt it?
Thank you very much in advance!

Use below mentioned code to convert blockhash into valid one /
const blockId="u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY=";
console.log(Buffer.from(blockId,'base64').toString("hex"))

Related

Sorting and Filtering Data - Flutter - Realtime Database

I have continuing data like this in my firebase realtime database. I want to get keys with values ​​greater than 75, their values and Province value.
{
"allboxes": {
"box00001": {
"boxes": {
"Electronic Box": 80,
"Glass Box": 25,
"Metal Box": 78,
"Oil Box": 90,
"Paper Box": 77,
"Plastic Box": 18
},
"info": {
"Id": "00001",
"Province": "Keçiören"
}
},
"box00002": {
"boxes": {
"Electronic Box": 95,
"Glass Box": 86,
"Metal Box": 45,
"Oil Box": 79,
"Paper Box": 98,
"Plastic Box": 18
},
"info": {
"Id": "00002",
"Province": "Etimesgut"
}
},
"box00003": {
"boxes": {
"Electronic Box": 55,
"Glass Box": 91,
"Metal Box": 79,
"Oil Box": 65,
"Paper Box": 50,
"Plastic Box": 100
},
"info": {
"Id": "00003",
"Province": "Çankaya"
}
}
}
}
I will use it in a Gridview.builder like this;
GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 220,
crossAxisCount: 2,
crossAxisSpacing: 15,
),
itemCount: boxesValuesList!.length,
itemBuilder: (context, index) => OpenedBoxesGrid(
boxesValuesList![index].toString(),
boxesKeysList![index],
provinceValuesList![index],
),
)
I tried this;
final greaterThan75ValueTaskRef = FirebaseDatabase.instance
.ref('allboxes')
.orderByChild('boxes/Oil Box')
.startAt(75);
And It returns this in print function.
I/flutter ( 6345): [{boxes: {Glass Box: 86, Plastic Box: 18, Electronic Box: 95, Metal Box: 45, Oil Box: 79, Paper Box: 98}, info: {Id: 00002, Province: Etimesgut}}, {boxes: {Glass Box: 25, Plastic Box: 18, Electronic Box: 80, Metal Box: 78, Oil Box: 90, Paper Box: 77}, info: {Id: 00001, Province: Keçiören}}]
But as I mentioned, I want to get keys in one list, their values in another list, and their province values in another list. How can I do that? I want to create three lists with the ordered equivalent of each element like this.
[Electronic Box, Metal Box, Oil Box, Paper Box, Electronic Box, Glass Box, Oil Box, Paper Box, Glass Box, Metal Box, Plastic Box]
[80, 78, 90, 77, 95, 86, 79, 98, 91, 79, 100]
[Keçiören, Keçiören, Keçiören, Keçiören, Etimesgut, Etimesgut, Etimesgut, Etimesgut, Çankaya, Çankaya, Çankaya]
When you read from the Firebase Realtime Database, you get a DataSnapshot object with all the data from the path that you read.
To get the key of a snapshot, call its key property.
To get just the a specific branch under the snapshot, use its child() method. So for example (assuming that boxesValuesList is the DataSnapshot with the result of the query you shared), to get a snapshot of just the boxes in your builder, you'd do boxesValuesList![index].child("boxes").
This can go multiple levels deep, so again assuming that boxesValuesList is the DataSnapshot with the result of the query you shared, you could get just the value of the Oilbox with: boxesValuesList![index].child("boxes").child("Oil Box").getValue() or with a shorthand notation: boxesValuesList![index].child("boxes/Oil Box").getValue().

Login with FormRequest in login page doesn't give any effects (Redirected 302)

I am trying to get Indonesian Dictionary from KBBI for NLP research purposes, I noticed that it is a protected page, and need to do authentication login first, here is the snippets I use with Scrapy Python
import scrapy
import re
import pandas as pd
from scrapy.http import FormRequest
from scrapy import Request
class scrape_kamus_kbbi(scrapy.Spider):
name = "kamus_kbbi"
list_url = []
ALP = [chr(x) for x in range(65, 91)]
sub_directory = "KBBI_FULL_HURUF"
page_set = [142, 232, 47, 76, 38, 23, 75, 50, 43, 44,
239, 85, 343, 32, 26, 274, 1, 69, 195, 178,
30, 11, 17, 2, 5, 7]
login_url = "https://kbbi.kemdikbud.go.id/Account/Login?ReturnUrl"
username = "myusername"
password = "mypassword"
full_directory = "C:/Users/User/Desktop/Data Science Journey/Data Science with Python/Crawling Script/Indonesian Words/" + sub_directory + ".csv"
for h in range(26):
for g in range(1,(page_set[h]+1)):
text_url = "https://kbbi.kemdikbud.go.id/Cari/Alphabet?masukan=" + str(ALP[h]) + "&masukanLengkap=" + str(ALP[h]) + "&page" + str(g)
list_url.append(text_url)
start_urls = [login_url]
def __init__(self):
self.words=[]
def parse(self, response):
self.log("Login page... Posting username & password")
formdata = {'Username': self.username, 'Password': self.password}
return FormRequest.from_response(response, formdata=formdata,
callback=self.after_login)
def after_login(self, response):
for i in range(len(self.list_url)):
yield Request(self.list_url[i], self.parse_page)
def parse_page(self, response):
self.log("Logged in... Grab All KBBI Words...")
kata = response.xpath('.//div[#class="col-md-3"]/a/text()').extract()
for x in range(len(kata)):
self.words.append(kata[x])
kumpulan_kata = pd.DataFrame(self.words, columns=["Kata"])
kumpulan_kata.to_csv(self.full_directory)
from scrapy import cmdline
cmdline.execute("scrapy runspider scapre_kbbi_kemdikbug.py".split())
but I still get redirected code 302
Redirecting (302) to <GET https://kbbi.kemdikbud.go.id/Account/Login?ReturnUrl=%2FCari%2FAlphabet%3Fmasukan%3DG%26masukanLengkap%3DG%26page29> from <GET https://kbbi.kemdikbud.go.id/Cari/Alphabet?masukan=G&masukanLengkap=G&page29>
I didnt know what goes wrong at this point. can anyone point a lead?
The formdata you pass to the request is wrong.
Should look like this:
formdata = {
'Posel': self.username,
'KataSandi': self.password
}
The correct request's params are these
But you instead send:
{
"__RequestVerificationToken": "some_token",
"Posel": "",
"KataSandi": "",
"IngatSaya": false,
"Username": "{self.username}",
"Password": "{self.password}"
}

Flutter decode one column of SQLite query result

My problem is that I have a sqlite Database with a column 'Rezepte'(Recipes) which contains a column 'Rezept_ID' and a column with the name('Rezept_Title') and I get a output like this:
{Rezept_ID: 0, Rezept_Title: [84, 104, 117, 110, 102, 105, 115, 99,
104, 102, 105, 108, 101, 116, 32, 105, 110, 32, 90, 105, 109, 116, 45,
83, 101, 115, 97, 109, 45, 75, 114, 117, 115, 116, 101, 32, 97, 117,
102, 32, 67, 104, 105, 108, 105, 45, 77, 97, 110, 103, 111, 45, 83,
97, 108, 97, 116]}
But I want for example(I'm not sure what the encoding means):
{Rezept_ID: 0, Rezept_Title: 'spaghetti'}
I found out that the numbers are just a decimal encoding and my question is:
How can I encode always just the column 'Rezept_Title' anscii? Or is there another encoding which dart shows in cleartext?
My current function to get the recipes is:
getRecipes() async {
Database db = await DatabaseHelper.instance.database;
// get all rows
List<Map> result = await db.query('Rezepte');
// print the results
return result.forEach((row) => print(row));
}
Looks like Rezept_Title is an array representation of a buffer instead of a string.
To make a string back out of a buffer array, use: new String.fromCharCodes(array)
In example:
getRecipes() async {
Database db = await DatabaseHelper.instance.database;
// get all rows
List<Map> result = await db.query('Rezepte');
// copy List of mutable Maps the ugly way
List<Map> parsedResult = [];
result.forEach((r) => parsedResult.add(Map<String, dynamic>.from(r)));
// make Rezept_Title string again
parsedResult.forEach((r) =>
r['Rezept_Title'] = new String.fromCharCodes(r['Rezept_Title'])
);
// print the parsed results
return parsedResult.forEach((row) => print(row));
}
You should get a print of:
{Rezept_ID: 0, Rezept_Title: "Thunfischfilet in Zimt-Sesam-Kruste auf Chili-Mango-Salat"}
PS: Better way to do this would be saving strings instead of buffers into database (and converting current records).

Ask about Radio in Autoit

How to put $Day into $Radio1 , $Week into $Radio2, $Month into $Radio3
And - $Radio1,$Radio2,$Radio3 into $RadioCheck ?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17)
$Radio2 = GUICtrlCreateRadio($Week, 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($Month, 24, 64, 113, 17)
GUISetState(#SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $RadioCheck = $Radio1,$Radio2,$Radio3 ; The problem is here
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1()
Local $Day, $Week, $Month
$LimitTime = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ;Get the current time (convert to seconds)
$Day = 86400 ; total seconds a Day
$Week = 604800 ; total seconds a Week
$Month = 2592000 ; total seconds a Month
_Example2($Example3, $Example4, $Example5-$RadioCheck)
EndFunc
Your $Day, $Week and $Month are local variables (inaccessible from global scope). More importantly: you are trying to set the text of your radio controls before you have declared or initialized these variables.
So how do you solve that? You have (at least) three options:
Option 1
Change your local variables from your function Example1() to global scope.
So change: Local $Day, $Week, $Month to Global $Day, $Week, $Month,
put it on top of your script and then
call the function Example1() before you create the GUI!
This is probably the easiest, yet dirtiest way, since any function could at any time change the data of your variables. In general try not to use global variables if possible.
Option 2
Change your radio controls to global variables and then change their text inside your Example1() function. Like this:
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17)
$Radio2 = ...
to
Global $Radio1 = GUICtrlCreateRadio("", 24, 16, 113, 17)
Global $Radio2 = GUICtrlCreateRadio("", 24, 40, 113, 17)
Global $Radio3 = GUICtrlCreateRadio("", 24, 64, 113, 17)
Note that you have to remove your undeclared variables! Then change the text of the controls in your Example1() function using:
GUICtrlSetData($Radio1, $Day)
GUICtrlSetData($Radio2, $Month)
GUICtrlSetData($Radio3, $Week)
Option 3a
This is the safest way. Let Example1() return the variables, either ByRef, or create and return an array. As array (untested):
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; We are now going to receive the return values (in this case an array) from our function:
Local $aDate = Example1() ; it is essential to call this function before we want to make use of $Date[0] to $Date[2].
; What happens is that the function (code block further down) named Example1() is being executed.
; This function will then RETURN us the array.
; Since Example1() returns an array, $aData will automatically become an array filled with the data of Example1()
#Region ### START Koda GUI section ### Form=
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($aDate[0], 24, 16, 113, 17) ; we are now setting the data for the three controls returned by Example1()
$Radio2 = GUICtrlCreateRadio($aDate[1], 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($aDate[2], 24, 64, 113, 17)
GUISetState(#SW_SHOW)
#EndRegion ### END Koda GUI section ###
; Local $RadioCheck = $Radio1,$Radio2,$Radio3 ; The problem is here ---- You do not need that and PLEASE READ THE ABOUT LOCAL AND GLOBAL VARIABLES!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1()
Local $aReturn[3] ;create a (Local) Array
$LimitTime =_DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ; Get the current time (convert to seconds)
$aReturn[0] = 86400
$aReturn[1] = 604800
$aReturn[2] = 2592000
Return $aReturn ; return the Array
EndFunc
Option 3b
You could also return the values ByRef :
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $Day, $Week, $Month ; we have to declare the variables for our Example1() function BEFORE we use them
Example1($Day, $Week, $Month) ; we here call our function with the previously declared variables as parameter.
; The function will then fill in the data into our variables before we use them to set the radio text
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17) ; set the data for the three controls
$Radio2 = GUICtrlCreateRadio($Week, 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($Month, 24, 64, 113, 17)
GUISetState(#SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1(ByRef $Day, ByRef $Week, ByRef $Month) ; NOTE: ByRef means that the given variables will be OVERWRITTEN, that also means that the variables MUST EXIST before the function is called
$LimitTime = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ; Get the current time (convert to seconds)
$Day = 86400
$Week = 604800
$Month = 2592000
EndFunc
Sources
Local/Global keyword.
Using Global, Local, Static and ByRef.
Func keyword.

IniRead array and pass to download function with progress bar

so i'm trying to work out how to get a downloader function working in a tool i'm working on, basically theres a tab with 3 download buttons, based on what button is clicked in the tab i'd like it to pass to one function, the downloder that will read the links from the ini file, with a progress bar in the tab I'll post the code bellow so you'll get an understanding
So it will download the files absolutely fine the only problem is when I start the app the download for the first file in the array starts automatically even though I didn't click the label in the tab, nor does the rest of the GUI function, I can't switch tabs as it just "freezes" then the download starts all over again if i comment out the case dwitch for $modlabel1 like so ";Case $modlabel1" it allows me to switch tabs etc just fine and I can switch tabs and click on the other 2 buttons and they will download as intended but the GUI stays on the mod tab till its finished, another small issue I have is i need the files to download with the same as the source file name, is that possible to do with InetGet?
Downloads Tab
Func _mods_gui()
$modsgui = GUICreate("Mods", 1270, 610, 5, 105, BitOR($ws_popup, $ws_border), $ws_ex_mdichild, $maingui)
GUISetBkColor(3487029)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $setgui, "int", 250, "long", 524288)
$progressbar1 = GUICtrlCreateProgress(10, 200, 1250, 50, $PBS_MARQUEE)
$modlabel1 = GUICtrlCreateLabel("Download" & #CRLF & "DayZ Epoch 1.0.5.1", 50, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modlabel2 = GUICtrlCreateLabel("Download" & #CRLF & "DayZ Overwatch 0.2.5", 450, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modlabel3 = GUICtrlCreateLabel("Download" & #CRLF & "Namalsk 0.75", 850, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modsgr2 = GUICtrlCreateGraphic(0, 25, 1270, 250)
GUICtrlSetState(-1, $gui_disable)
GUICtrlSetGraphic(-1, $gui_gr_color, 0, 2368548)
GUICtrlSetGraphic(-1, $gui_gr_rect, 0, 0, 1270, 250)
GUISetState(#SW_SHOW, $modsgui)
EndFunc
While Switch Case
Case $modsgui
Switch $nmsg[0]
Case $modlabel1
_downloadmod(0)
Case $modlabel2
_downloadmod(1)
Case $modlabel3
_downloadmod(2)
EndSwitch
Download Array
Func _downloadmod($mod)
$modarrayread[3] = [IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_epoch", Default), IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_overwatch", Default), IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_namalsk", Default)]
$dwnmod = InetGet($modarrayread[$mod], #ScriptDir & "\Mods\$name.zip", 1, 1)
Do
Sleep(50)
$prc = Round(InetGetInfo($dwnmod, 0) / (InetGetInfo($dwnmod, 1)) * 100)
GUICtrlSetData($progressbar1, $prc)
Until InetGetInfo($dwnmod, $INET_DOWNLOADCOMPLETE)
EndFunc
INI
[mod_links]
mod_epoch=http://files.xexgaming.com/mods/#DayZ_Epoch1051.zip
mod_overwatch=http://files.xexgaming.com/mods/#DayZOverwatch.zip
mod_namalsk=http://files.xexgaming.com/mods/#Namalsk.zip
Credits to Trojan for the help with the array, worked out how to get the parameters using his example
I worked with the example script in the help for GUICtrlCreateProgress as base and wrote a script which hopefully does what u wanted it to do.
If you have any questions feel free to ask :)
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
Example()
Func Example()
Local $progressbar1, $button1, $button2, $button3
Local $downarrayread[3] = [IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_1", Default), IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_2", Default), IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_3", Default)]
GUICreate("Downloads", 220, 100, 100, 200)
$progressbar1 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
$button1 = GUICtrlCreateButton("Start 1", 5, 70, 70, 20)
$button2 = GUICtrlCreateButton("Start 2", 75, 70, 70, 20)
$button3 = GUICtrlCreateButton("Start 3", 145, 70, 70, 20)
GUISetState(#SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $button1
$hDownload = InetGet($downarrayread[1], #ScriptDir & "/Downloads/File1", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
Case $button2
$hDownload = InetGet($downarrayread[2], #ScriptDir & "/Downloads/File2", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3+33.33)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
Case $button3
$hDownload = InetGet($downarrayread[3], #ScriptDir & "/Downloads/File3", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3+66.66)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
EndSwitch
WEnd
EndFunc ;==>Example

Resources