-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to generate coin_info #17
Comments
fixed it.
|
its not working in my case |
Do I need to change my amount to any other format? Please suggest |
@sibitha-bijesh no |
Still have problem,watch this: but this https://www.chiaexplorer.com/blockchain/coin/0x5615ca8684e921b6bf2c0542bd5f878df62bf3c0154856a2793eae5167a17461 |
我猜大概是因为后两笔金额过小? 大于0.001的时候是正确的 |
解决了 |
const { createHash } = require("crypto");
const parentCoinInfo = 'f2a908698aa5c00ecbd7792bf3ce801317f53ed6544ad8e6e8ba4bd54853b9dd';
const puzzleHash = 'a73e6bcbdcdf7acafb63d240fc67f53115768a991be645246cac2f3a1ffef53b';
const amount = 1049500000000
const getCoinInfo = function (parentCoinInfo, puzzleHash, amount) {
const a = Buffer.from(parentCoinInfo, 'hex')
const b = Buffer.from(puzzleHash, 'hex')
let amountHex = amount.toString(16);
if (amountHex.length % 2 == 1) {
amountHex = '0' + amountHex
}
const c = Buffer.from(amountHex, 'hex');
const d = Buffer.concat([a, b, c], a.length + b.length + c.length);
const hash = createHash('sha256');
hash.update(d);
return hash.digest('hex')
}
console.log(getCoinInfo(parentCoinInfo, puzzleHash, amount)) |
官方只给出了python计算coin ID方法, 找了一圈没找到其他语言计算coin ID方法。 在 chia-blockchain/chia/rpc/full_node_rpc_api.py文件中导入 Coin:
在FullNodeRpcApi类中添加方法: async def get_coin_id(self, request: Dict):
"""
Returns coin id
"""
return {"coin_id": Coin(hexstr_to_bytes(request["parent_coin_info"]), hexstr_to_bytes(request["puzzle_hash"]), int(request["amount"])).name()} get_routes方法返回值中加一行: |
试了一下 这笔计算的金额的hex前面要再加2个0 .. 至于为什么 目前判断是如果amount转换的第一位是字母 需要再补2个0 |
求一个php版本的转换coinid. 感激不尽 |
没学过php 按照步骤上网搜了一下写了一个:
用的菜鸟教程的在线编辑器写的 没有怎么处理格式 将就看吧 思路大概是这么个思路 |
非常感谢! |
For all interested, I've created the |
const parentCoinInfo = 'f2a908698aa5c00ecbd7792bf3ce801317f53ed6544ad8e6e8ba4bd54853b9dd'; I use get_coin_info from chia-utils, get 0x38976d54b506c2a955022601368c943fa081ffce1fcfeaa1bf95bfa10d714f54 1.0495 * 1000000000000 = 1049500000000.0001, if not use BigInt |
@xw332 Please use |
but 1049500000000 / 1000000000000 * 1000000000000 = 1049500000000.0001 |
Yes, there seems to be an issue with large numbers, I'll take a look. |
求一个java的~ |
@xw332 Bug has been fixed in |
碰见一个情况不一致的
amount的16进制为89173700,转换的第一位不是字母。 这个尝试了下,是头部添加两个0生成的。 请问一下,这种需要根据什么情况判断? |
参照大佬的https://github.com/CMEONE/chia-utils 写了go的实现 |
因爲uint需要使用多一位來表示正負數數,所以當amount佔用的位數剛好爲8的倍數時,需要補多一位,因此在某些情況下補一個0並不夠,要補兩個0。 |
所以以下是我的補0方法。 amountHex = '0'.repeat((Math.ceil(Math.log2(amount))+8>>3<<1)-amountHex.length) + amountHex |
@qwIvan What version are you running (use |
非常好用 已经用上了 感谢大佬 不过有个小疑问 为什么要先右移3位再左移1位而不是直接右移2位呢 |
coinID == sha256(parent_ID + puzzlehash + amount)
I found it from https://chialisp.com/docs/doc2
I tried it with Nodejs and still not correct.
console.log(CryptoJS.SHA256('f7e09a94c5da73019577b288aeedaf4750540ecca091bb5c4bcf45dacb3a0485' + 'ee12091f293040e42999c64d471ec9a65692f1dde0c42a4936d80e25a8d0535c' + 299700000000).toString()) // return e8ad8111fd2761792b9b39a531117ca8edcbc4ba65b2c3d9472c63dd76876731 not matched 6dddefd62523efccacf35e0cac24cc5348dde8f40ae48be1c563a9404e8251fe
So what the type of these params are?
Can someone provide any examples? Thank you.
The text was updated successfully, but these errors were encountered: