Skip to content

the transaction created by libs can't send to cardano-node #16

@islishude

Description

@islishude

shelley cardano-node: v1.14.2
shelley cardano-wallet: 2020.7.6-shelley

code with commit 320191c

#![allow(unused_variables, unused_imports)]

use cardano_serialization_lib::{self as adalib, crypto};
use cbor_event::{self as cbor};

pub fn main() {
    let xprv = "xprv1wq9th6qy7ej8w03cgas2lzwvzncvwaje8ek8lps6u6mwyhtpaewap0w2f9hhrpg6tvrffcvz5ecevvhfl6vnznswss96kqyncm2drut3kfps0pv0r4q3fuy6urzs52ywdpzx55muncgf283fr378hwzwp5p27ewe";
    let xprv = crypto::Bip32PrivateKey::from_bech32(xprv).unwrap();

    let xpub = xprv.to_public();
    // crypto::blake2b224 visibility changed
    let keyhash = crypto::blake2b224(&xpub.as_bytes()[0..32]).to_vec();
    let keyhash = crypto::AddrKeyHash::from_bytes(keyhash).unwrap();
    let cred = adalib::address::StakeCredential::from_keyhash(&keyhash);
    let payment = adalib::address::EnterpriseAddress::new(0, &cred);

    let mut inputs = adalib::TransactionInputs::new();
    let txid = "2558aad25ec6b0e74009f36dc60d7fec6602ce43d603e80c9edde9dd54c78eb4";
    let txid = crypto::TransactionHash::from_bytes(hex::decode(txid).unwrap()).unwrap();
    let input = adalib::TransactionInput::new(&txid, 0);
    inputs.add(&input);

    let mut outputs = adalib::TransactionOutputs::new();
    let output = adalib::TransactionOutput::new(&payment.to_address(), adalib::Coin::new(9000000));
    outputs.add(&output);

    let txbody =
        adalib::TransactionBody::new(&inputs, &outputs, adalib::Coin::new(1000000), 832163);

    let vkwt = txbody.sign(&xprv.to_raw_key());
    let mut vkwts = crypto::Vkeywitnesses::new();
    vkwts.add(&vkwt);
    let mut witness_set = adalib::TransactionWitnessSet::new();
    witness_set.set_vkeys(&vkwts);
    let newtx = adalib::Transaction::new(&txbody, &witness_set, None);

    use std::io::prelude::*;
    let mut file = std::fs::File::create("tx.raw").unwrap();
    file.write_all(&cbor::cbor!(&newtx).unwrap()).unwrap();

    // println!("{}", hex::encode(cbor::cbor!(newtx).unwrap()));
}

the signed tx with hexify

83a400818258202558aad25ec6b0e74009f36dc60d7fec6602ce43d603e80c9edde9dd54c78eb400018182581d60c5fb57853a4a5bbb13bcd494ee0facd4e1fca33720a640664df151341a00895440021a000f4240031a000cb2a3a10081825820c6e47dceb9235ad31fec01ef3e34b02839d22fb583cd28fac7ec81ebbe653a395840e94817956d902702ed6172db8edca0193b33aba511a72e1998cc18aa492be8cffaca96c8305ffbb2836c3c04c886e23302e222b99185b87b701a40a10c50660ff6

and then post signed tx to cardano-wallet

curl -X POST 'http://10.60.82.100:8090/v2/proxy/transactions' -H 'Content-Type: application/octet-stream' --data-binary tx.raw

the response data

{
  "code": "malformed_tx_payload",
  "message": "I couldn't verify that the payload has the correct binary format. Therefore I couldn't send it to the node. Please check the format and try again."
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions