Comments (12)
- Agreeing with above opinions that
fromSolidityAddress
should be dropped in favor offromEvmAddress
overloads. - Also consider the following code. I assume developers are going to be doing this themselves a lot now? Why don't we do it for them with a single SDK call?
// identifying prefix for account-num alias (aka long-zero)
const LONG_ZERO_PREFIX = '0x000000000000000000000000'
let contractId;
// given a 20 byte string contractAddress of form 0x....
if (contractAddress.startsWith(constants.LONG_ZERO_PREFIX)) {
// assumes 0 value shard and realm and converts adddress to num
contractId = ContractId.fromSolidityAddress(contractAddress);
} else {
// uses hex address instead of num in id
contractId = ContractId.fromEvmAddress(0, 0, contractAddress);
}
from hedera-sdk-reference.
My thoughts
- Add a
fromEvmAddress(address)
andfromEvmAddress(shard, realm, address)
- former assumes 0 shard and realm. Both cases set a null not a 0 num - Deprecate the other 2 (
fromEvmAddress()
andfromSolidityAddress()
) after some time - Explore a future Mirror Node query using
api/v1/accounts/{address}
. To be clear I'm not saying as part offromEvmAddress
but rather as a MAPI query, similar to HAPI queries.
from hedera-sdk-reference.
In my opinion,
fromAddress
is a bit too generic and might confuse the user. I agree with @Nana-EC, it should befromEvmAddress
and we should deprecatefromSolidityAddress
.fromEvmAddress
should return0.0.Number
and then0.0.evmAddress
if the first one if not possible- I think we need to have a way for the user to convert EVM address to account/contract id through SDK. Maybe we can implement
client.fromEvmAddress
so you don't need to worry about specifying the network for now.
SDK talking to the mirror node is becoming unavoidable. The mirror node currently supports smart contract state queries now so I think that in the future the SDK should switch to query smart contract state from the mirror node instead of the consensus node so the users don't need to pay for the transaction fee.
from hedera-sdk-reference.
Gentle nudge on the conversation: Not all languages can do overloads (Namely Rust in my case, Go too out of the SDKs we have) nor default parameter arguments (again Rust and likely Go), although #128 (comment) does seem to at least partially address this.
from hedera-sdk-reference.
From an API design standpoint if we've addressed the issue and it scales I think we're good as is and should just deprecate fromSolidityAddress()
since as you said fromEvmAddress()
can handle both evm formats now.
from hedera-sdk-reference.
In my opinion, fromAddress
is a bit too generic in term of naming. It would also cause a confusion.
from hedera-sdk-reference.
Note: This PR does the second sub point to the first issue! It only adds the checks inside the present methods and navigates the flow based on the input.
-
Next steps should be to decide whether or not to create the generic method
fromAddress()
(and if we will deprecate the present ones), since the present methods have different inputs and how do we handle that? -
Also the fact that
fromEvmAddress()
sets a default0
value for thenum
field, despite the fact that if you query the mirror node for the same evm address, you will get the actualnum
value.
from hedera-sdk-reference.
I am in favor of the one size fits all fromAddress
that you talked about as the third option and then depreciation of the other methods. It simplifies everything and just works. Here here.
from hedera-sdk-reference.
One thing to consider in general is that in JS we do not have method overloading. So this is the reason why we ended up with so many different method signatures. The same thing should be considered here plus the fact that (I assume) we do not want to make any breaking changes, meaning that present methods fromEvmAddress()
and fromSolidityAddress()
should stay the same and only add handlers there if any and add new method for example fromAddress()
and design it in a way that would handle all cases (because we are kind of running out of free method signatures already ๐)
@david-bakin-sl On your second point -> this check is already added to both methods fromEvmAddress()
and fromSolidityAddress()
so that even if users pass the wrong format address, the flow will be passed to the correct function
On the topic about getting the actual account num from the mirror node - I would agree that we should enhance and make a query which calls the mirror node and gets the actual num of the AccountId
@Nana-EC @pathornteng
from hedera-sdk-reference.
-
if we have generalized method
fromAddress(evmAddress, shard = 0, realm = 0)
note: input parameters should be reordered if we want for shard and realm to default to0
because if they are beforeevmAddress
(in JS) they cannot be optional and users should always pass a value for them- if
evmAddress
is a long-zero format โ pass tofromSolidityAddress()
method which parses the bytes to a propershard, realm, num
format forAccountId
- otherwise generate
AccountId
withshard
andrealm
from the input (if not set - assign0
as default value) and0
fornum
field andevmAddress
from the input- log a message or add to method description that a
0
will be set for thenum
field and the user should query the mirror node for the actualnum
field. We can even throw an exception if a user tries to use the generatedAccountId
without the propernum
value i.e "Account num isnull
, please query the mirror node and get the actual value"?
- log a message or add to method description that a
- if
-
design the Mirror node call
- can take
evmAddress
as a string orAccountId
object and query the mirror node withexecute(client)
so that we can get the network from the client and query the proper mirror node and after getting the result โ automatically set thenum
from the mirror node to thenum
field of the passedAccountId
object. An open question here would be if we add this functionality to theAccountId/ContractId
objects as a method or a separate call... IMO an object method would be better
- can take
@mgarbs @Nana-EC @pathornteng @david-bakin-sl
from hedera-sdk-reference.
(w.r.t. reordering the parameters so shard+realm can be defaulted to 0: I suggest they be reversed from the standard definition to be address then realm then shard. It's already the case that the three components are all integers, the order is easily confused, IMO reverse is better than rotate.)
(Although this JS consideration of no overloading yet default-to-zero is painful in this regard: this signature with 3 consecutive longs, where we have to reverse it from the standard. Typing doesn't help so you can't just say it works fine in TypeScript. High possibility for confusion in the future. IDE hints or not. Gosh. Maybe two separate names is better, just not the ones we've got. And we don't even have shards+realms yet. Sigh. Something like fromAddress
(1 arg version) and fromFullAddress
or fromFullyQualifiedAddress
(3 arg version)? (Whatever the name we give officially to the "full" shard+realm+number if we need to distinguish it from the current 0+0+number.) I dunno. This might be something ... requires even more consideration of the user POV over time?)
(Yet another possibility: use shard+realm+number in that order and everyone always has to type ...(0,0,addr)
and that's just the way it is. Why not? Everything else we document and put into production (e.g., hashscan) always uniformly puts the 0.0.n
version out there, never elides the 0.0.
prefix. How hard would it be to just type the 0,0,
when you need it? It would sure eliminate this confusion.)
(Proves once again that little-endian is the proper choice for almost everything, networking precedent aside ...)
from hedera-sdk-reference.
@pathornteng @Nana-EC @izik1 @david-bakin-sl @mgarbs
Continuing the conversation from above, currently, we do have:
- handlers in both methods so that the flow can be passed to the correct method
- MAPI call that queries the mirror node so that a user can get his actual
num
field whenAccountId/ContractId
is generated from an actualevmAddress
Shall we add a generic method fromAddress()
?
It would be pretty hard to unify this method in languages throughout all SDKs, reasons:
No overloads -> JS, Rust, Go
No default/optional parameters -> Rust, Go
In JS we can design it like this: fromAddress(address, shard = 0, realm = 0)
which will handle both evm address formats in Hedera..
Or we can leave it like this and just deprecate fromSolidityAddress()
since fromEvmAddress()
can handle both evm formats now!
from hedera-sdk-reference.
Related Issues (20)
- Add doc reference for `TokenGrantKycTransaction`
- HIP-745: Optionally send transaction data without required transaction fields HOT 2
- Add design document for HIP-745 HOT 1
- Add doc reference for HIP-646
- Add doc reference for HIP-657
- Add design doc for node selection algorithm used in the SDKs
- Add design doc for retry feature in the SDKs
- Add optional parameter to `ContractCreateFlow` to avoid File removal HOT 2
- Add retry logic on `.getReceipt` on network response excluding "Success" HOT 1
- ABI support in SDKs
- Review the client and retry features in the SDKs
- `Client` should allow disabling automatic address book update
- Add support to return token balances for an account and contract account
- Specify a per-method / per-error code retry policy on the grpc client.
- HIP-796:ย Lockable Fractional Amounts of Fungible Tokens on Hedera
- HIP 844: Handling and externalisation improvements for account nonce updates
- Add doc reference HIP-765
- Add doc reference HIP-844 HOT 1
- ci: [2024-Q3] CI/CD Audit Story
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 hedera-sdk-reference.