Comments (26)
ok bro. Thanks bro π
from libethc.
also i have a question. Can we encode uint256 data types using this new raw data type.... because if i want to send this data back to the RPC function i need a container that holds all of the digits.
Easy:
struct eth_abi abi; mpz_t mpz; // 0xfff or 123 or load from uint64 etc.. mpz_init_set_str(mpz, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0); eth_abi_init(&abi, ETH_ABI_ENCODE); eth_abi_mpint(&abi, mpz); // ...Here's the gmp manual: https://gmplib.org/manual/
ok thanks bro π
from libethc.
i was trying.... i try to access the struct members and see it. but i lost...... i think i need some hand pls π
Do you want to export mpz_t
to char*
? It should be like this:
char *str;
gmp_asprintf(&str, "%Zd", r1);
printf("str: %s\n", str);
free(str);
from libethc.
int eth_abi_mpint(struct eth_abi *abi, mpz_t *mpz)
int eth_rlp_mpint(struct eth_rlp *rlp, mpz_t *mpz)
can u tell me when we will see this feature implmented ?
from libethc.
As soon as I have free time. It's not hard to implement.
from libethc.
Hi @DerXanRam. Can you pull the dev branch and test the eth_abi_mpint
? efd7ee0
from libethc.
Hi @DerXanRam. Can you pull the dev branch and test the
eth_abi_mpint
?
Ok..
I'm on it bro π
from libethc.
This the code i am testing with it
void decoder(char *data)
{
struct eth_abi abi;
MP_INT r1, r2;
uint32_t timee;
int a;
// initialize abi struct from encoded abi
eth_abi_from_hex(&abi, data, -1);
// decoding happens here
eth_abi_mpint(&abi,&r1);
eth_abi_mpint(&abi,&r2);
eth_abi_uint32(&abi, &timee);
// free the abi struct
eth_abi_free(&abi);
printf("decoded address: %d\n", r1);
printf("decoded address: %d\n", r2);
printf("decoded address: %d\n", timee);
}
and it throughs this error
[{
"resource": "/usr/include/x86_64-linux-gnu/gmp.h",
"owner": "cpptools",
"severity": 8,
"message": "conflicting declaration of C function βstd::ostream& operator<<(std::ostream&, mpq_srcptr)β",
"source": "gcc",
"startLineNumber": 2286,
"startColumn": 33,
"endLineNumber": 2286,
"endColumn": 33
},{
"resource": "/usr/include/x86_64-linux-gnu/gmp.h",
"owner": "cpptools",
"severity": 8,
"message": "conflicting declaration of C function βstd::ostream& operator<<(std::ostream&, mpf_srcptr)β",
"source": "gcc",
"startLineNumber": 2287,
"startColumn": 33,
"endLineNumber": 2287,
"endColumn": 33
},{
"resource": "/usr/include/x86_64-linux-gnu/gmp.h",
"owner": "cpptools",
"severity": 8,
"message": "conflicting declaration of C function βstd::istream& operator>>(std::istream&, mpq_ptr)β",
"source": "gcc",
"startLineNumber": 2289,
"startColumn": 33,
"endLineNumber": 2289,
"endColumn": 33
},{
"resource": "/usr/include/x86_64-linux-gnu/gmp.h",
"owner": "cpptools",
"severity": 8,
"message": "conflicting declaration of C function βstd::istream& operator>>(std::istream&, mpf_ptr)β",
"source": "gcc",
"startLineNumber": 2290,
"startColumn": 33,
"endLineNumber": 2290,
"endColumn": 33
}]
from libethc.
Okay, could you open ethc/abi.h
and put #include <gmp.h>
before #ifdef __cplusplus
and test?
from libethc.
ok wait...
from libethc.
The previous erros are gone now. But it runs and throws this error
realloc(): invalid pointer
in file abi.c at this line 663
mpz_import(mpz, 32, 1, sizeof(uint8_t), 0, 0, bytes);
from libethc.
You have to initialize r1
and r2
first (mpz_init(r1)
etc).
from libethc.
To print mpz
s, do: gmp_printf("%Zd\n", r1);
from libethc.
this is the code
void decoder(char *data)
{
struct eth_abi abi;
MP_INT r1, r2;
mpz_init(r1);
mpz_init(r2);
uint32_t timee;
int a;
// initialize abi struct from encoded abi
eth_abi_from_hex(&abi, data, -1);
// decoding happens here
eth_abi_mpint(&abi,&r1);
eth_abi_mpint(&abi,&r2);
eth_abi_uint32(&abi, &timee);
// free the abi struct
eth_abi_free(&abi);
printf("decoded address: %d\n", r1);
printf("decoded address: %d\n", r2);
printf("decoded address: %d\n", timee);
}
and it throws this error
[{
"resource": "/home/biruk/Documents/eth/arb+tbot/uniswap.h",
"owner": "C/C++: IntelliSense",
"code": "413",
"severity": 8,
"message": "no suitable conversion function from \"MP_INT\" to \"mpz_ptr\" exists",
"source": "C/C++",
"startLineNumber": 219,
"startColumn": 12,
"endLineNumber": 219,
"endColumn": 14
}]
gmp_printf("%Zd\n", r1);
and is this the only way to print it...what about passing to char* ?
from libethc.
Try replacing MP_INT
with mpz_t
and is this the only way to print it...what about passing to char* ?
gmp_printf
is compatible with printf
, so, just works: gmp_printf("%Zd %s\n", r1, "test");
from libethc.
and now this functions parameters are not compatible with mpz_t
eth_abi_mpint(&abi,&r1);
eth_abi_mpint(&abi,&r2);
the error is
[{
"resource": "/home/biruk/Documents/eth/arb+tbot/uniswap.h",
"owner": "C/C++: IntelliSense",
"code": "167",
"severity": 8,
"message": "argument of type \"mpz_t *\" is incompatible with parameter of type \"__mpz_struct *\"",
"source": "C/C++",
"startLineNumber": 226,
"startColumn": 22,
"endLineNumber": 226,
"endColumn": 22
},{
"resource": "/home/biruk/Documents/eth/arb+tbot/uniswap.h",
"owner": "cpptools",
"severity": 8,
"message": "cannot convert β__mpz_struct (*)[1]β to β__mpz_struct*β",
"source": "gcc",
"startLineNumber": 226,
"startColumn": 36,
"endLineNumber": 226,
"endColumn": 36
},{
"resource": "/home/biruk/Documents/eth/arb+tbot/uniswap.h",
"owner": "C/C++: IntelliSense",
"code": "167",
"severity": 8,
"message": "argument of type \"mpz_t *\" is incompatible with parameter of type \"__mpz_struct *\"",
"source": "C/C++",
"startLineNumber": 227,
"startColumn": 22,
"endLineNumber": 227,
"endColumn": 22
},{
"resource": "/home/biruk/Documents/eth/arb+tbot/uniswap.h",
"owner": "cpptools",
"severity": 8,
"message": "cannot convert β__mpz_struct (*)[1]β to β__mpz_struct*β",
"source": "gcc",
"startLineNumber": 227,
"startColumn": 36,
"endLineNumber": 227,
"endColumn": 36
}]
from libethc.
No, mpz_t
is a pointer itself. Just do: eth_abi_mpint(&abi, r1);
from libethc.
it throws runtim error
/usr/bin/ld: /tmp/ccBXKWZ4.o: undefined reference to symbol '__gmpz_init'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgmp.so.10: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
from libethc.
Try adding -lgmp
to args
in tasks.json
from libethc.
it runned succsussfuly and using printf
it gives false decode result and using gmp_printf
correct result.
using printf
decoded address: -10256
decoded address: -10240
decoded address: 1690645691
using gmp_printf
6729450845017214267
6777196
decoded address: 1690645691
from libethc.
Yes, becuase printf
doesn't know about the mpz_t
. To print in hex format, do gmp_printf("%Zx\n", r1)
from libethc.
also i have a question. Can we encode uint256 data types using this new raw data type.... because if i want to send this data back to the RPC function i need a container that holds all of the digits.
from libethc.
Yes, becuase
printf
doesn't know about thempz_t
. To print in hex format, dogmp_printf("%Zx\n", r1)
so how to store the data to char* or int for further processing from this data type?
from libethc.
also i have a question. Can we encode uint256 data types using this new raw data type.... because if i want to send this data back to the RPC function i need a container that holds all of the digits.
Easy:
struct eth_abi abi;
mpz_t mpz;
// 0xfff or 123 or load from uint64 etc..
mpz_init_set_str(mpz, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0);
eth_abi_init(&abi, ETH_ABI_ENCODE);
eth_abi_mpint(&abi, mpz);
// ...
Here's the gmp manual:
https://gmplib.org/manual/
from libethc.
Yes, becuase
printf
doesn't know about thempz_t
. To print in hex format, dogmp_printf("%Zx\n", r1)
so how to store the data to char* from this data type?
i was trying.... i try to access the struct members and see it. but i lost...... i think i need some hand pls π
from libethc.
Closing the issue. Added in efd7ee0
from libethc.
Related Issues (20)
- abi: add functions to encode/decode strings
- ci: run unit tests on every branch HOT 13
- deps: make `secp256k1` submodule HOT 6
- abi: `eth_abi_mpint` should encode `mpz`s as integers, not bytes. HOT 11
- How should I compile on Windows? HOT 2
- cpp: add cpp wrappers
- pkg: publish the library to homebrew, apt, pacman, yum etc. HOT 1
- cmake: Compatibility with CMake < 3.5 will be removed from a future version of CMake. HOT 1
- gcc: stack smashing detected error when building using gcc and running tests HOT 2
- RPC responded Insufficient funds even if i have funds HOT 33
- ABI parameters decoding for arrays data types are not working properly HOT 28
- Strange buffer hex post signature HOT 6
- ecdsa: add public key recovery functions
- Encode array of tuples HOT 6
- abi: cannot encode/decode tuples HOT 4
- [libsecp256k1] illegal argument: secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx) HOT 5
- ecdsa: `eth_ecdsa_sign` should not sign recoverable signatures by default HOT 2
- Loading account from a private key HOT 2
- Obtaining ECDSA r and s values correctly HOT 3
- When use eth_rlp_uint(), the result of rlp serialization is inconsistent with the result of rlp encode in the go-etherum library. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libethc.