aeternity / aepp-sdk-go

Golang SDK to interact with the Æternity blockchain
ISC License
18 stars 10 forks source link

PostTransaction failed: Invalid api encoding #5

Closed guotie closed 5 years ago

guotie commented 5 years ago

I use the Spend method in helper.go, I got error

{
    "reason": "Invalid api encoding"
}

The tx and post request is following:

curl -X POST "http://192.168.1.122:3013/v2/transactions" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"tx\": \"tx_77HAufwc2o474Dk39cz92mJZwWfThZYoAd3M7wka9KY7dWeeeBzxpYTwAB3iReJ5XAUKtyWS3YXdRsX3MDX1yUmck2ewFhwcVB7nWybnBtLwopyvGfh6gLxEk2oY4H2cF9Lv5ZwBVdgGjyYn4UdkeadFBv8fEbaaorFfbaqWMyD15ikQjC6jWZjk6aF4Erq57DfJT1d3s5coeck9ikD3aKHSXj3ZcHVo6ujevkRVBiwPauHPqkVBB\"}"

How to solve it

guotie commented 5 years ago

I change the tx encode from base58 to base64, and the error changed to:

 {"reason":"Invalid tx"}

the tx is:

tx_+K0LAfhCuECVAoKRHAA0340xaWjT794Jek19ClmfDIDUn7bZJzXqCFgc6fQQ/ryNNpw0FF/YPXU8JuHVERtCtUnZTdsbPKIKuGX4YwwBoQEZSfC6lpjA3coVQ76+43LwY86L6TBhcQFcMh3xOD2Yr6EBL4SNMItRNjNretVJr40fLGgJQOksMEqmhCFeFzAfg++IRWORgkT0AACGvv5vZyAAgi48iCg1/awAI5AAgBwMi5E=
wx-shi commented 5 years ago

// SignEncodeTx sign and encode a transaction func SignEncodeTx(kp *Account, txRaw []byte) (signedEncodedTx, signedEncodedTxHash, signature string, err error) { // add the network_id to the transaction msg := append([]byte("ae_mainnet"), txRaw...) // sign the transaction sigRaw := kp.Sign(msg) if err != nil { return } // encode the message using rlp rlpTxRaw, err := createSignedTransaction(txRaw, [][]byte{sigRaw}) // encode the rlp message with the prefix //signedEncodedTx = encodeP(PrefixTx, rlpTxRaw) signedEncodedTx = encodeP64(PrefixTx, rlpTxRaw) // compute the hash rlpTxHashRaw, err := hash(rlpTxRaw) signedEncodedTxHash = encodeP(PrefixTxHash, rlpTxHashRaw) // encode the signature signature = encodeP(PrefixSignature, sigRaw) return } func encodeP64(prefix HashPrefix, data []byte) string { return fmt.Sprint(prefix, encode64(data)) } func encode64(in []byte) interface{} { c := hashSha256(hashSha256(in)) return base64.StdEncoding.EncodeToString(append(in, c[0:4]...)) }

wx-shi commented 5 years ago

老兄 中国人? 就是一个加密算法用错了 encodeP里面用的是base58 然而tx需要base64

wx-shi commented 5 years ago

see: https://github.com/aeternity/protocol/blob/master/epoch/api/api_encoding.md

guotie commented 5 years ago

用base58时,报"Invalid api encoding"

改成base64之后报"Invalid tx"

老外的项目真tmd不靠谱

wx-shi commented 5 years ago

兄弟我的没毛病了 你是不是fee没调大 fee得为17000+

wx-shi commented 5 years ago

我们交易所都上线了,完全没毛病

wx-shi commented 5 years ago

只是错误返回不明显 我当初fee也是默认为1 结果也报Invalid tx

guotie commented 5 years ago

fee设置成17000,还是 Invalid tx

guotie commented 5 years ago

thank you very much. @wx-shi

It my fault, I got wrong nonce.