BitShares Forum
Main => General Discussion => Topic started by: ElMato on October 27, 2014, 05:06:58 am
-
I know that devs are involved in more important things, but it would be really helpful to have a simple example of how to create two types of raw transactions.
1) Account register.
2) Asset transfer.
Number one is useful when i want to register an account on behalf of other person. (ie: Mobile Client signup process)
We will create the private keys like wallet_account_create does.
So far, this is what i have diving into the source code.
uint32_t utc_seconds;
uint64_t delegate_slate_id;
VARINT n_ops; (number of ops)
-- register account operation
uint8_t operation_type
VARINT name_length
char[name_length] name
VARIANT public_data (json string serialized as VARIANT?)
uint8_t[33] owner_key
uint8_t[33] active_key
uint8_t delegate_pay_rate
uint32_t account_type
VARINT data_length
char[data_length] data
--- withdraw operations
....
-- signatures
....
is this ok?
Then i have to provide the signatures of the spent record ids (from the pay account) that pays for the transaction fee.
For this i need to know the blockchain format.
I remember that drltc was working on this, is there any documentation to look?
Other questions:
Do we have an equivalent of change addresses in bitshares?
Or balance records are modified "in place"?
Do we have any tool in python/ruby to read the blockchain and extract information?
-
Balance records are modified in place, but if you want a change address you can withdraw the whole balance and send to two new balances.
It would probably be easier to construct custom transactions in JSON format and then ask the C++ to serialize them.
-
BM, thanks for your response.
Just let me know if I am on the right track.
wallet_account_balance_ids account
returns the complete "UTXO" set for the account?
Then i can use the balance ids to make this ...
{
"trx": {
"expiration": "20141027T205151",
"delegate_slate_id": null,
"operations": [{
"type": "register_account_op_type",
"data": {
"name": "[put a name here]",
"public_data": null,
"owner_key": "[Public Key BTSX format]",
"active_key": "[Public Key BTSX format]",
"delegate_pay_rate": 255,
"meta_data": {
"type": "public_account",
"data": ""
}
}
},{
"type": "withdraw_op_type",
"data": {
"balance_id": "[Balance Record ID]",
"amount": 50000,
"claim_input_data": ""
}
}
],
"signatures": [
"[Signature for the withdraw]"
]
}
}
Questions:
0) Is the above Json enough?
1) How is the signature generated ?
(required_signatures adds balance_record.owner() but i can't figure what is signing)
2) How do i go from Json -> Hex? Is there any "createrawtransaction"?
-
We will need to add an RPC call that will create a raw transaction... and return the hash of the raw transaction and list of required signatures for the purposes of signing.
The signature must be on the full transaction.
-
It would be great if we can have our own blockcypher.com (or chain.com) or ask them to integrate bitshares.
I managed to create and broadcast a raw transaction using the code below.
Please give me some directions:
1) Who do i track records ids of accounts that are not in the wallet db? (read only accounts)
Should i export the wallet to json and add a new account_record_type?
#include <iostream>
#include <vector>
#include <bts/blockchain/transaction.hpp>
#include <fc/crypto/elliptic.hpp>
#include <fc/io/json.hpp>
#include <fc/crypto/hex.hpp>
#include <bts/utilities/key_conversion.hpp>
using namespace bts::blockchain;
using namespace bts::utilities;
int main(int argc, char** argv)
{
const std::string tx_json = R"(
{
"expiration": "20141028T085151",
"delegate_slate_id": null,
"operations": [{
"type": "register_account_op_type",
"data": {
"name": "justtesting",
"public_data": null,
"owner_key": "BTSX6yNA6Kc1qYSUt1ppFe8oPKcnWGHCg11VLKTY36V9jfyQvswjdh",
"active_key": "BTSX6yNA6Kc1qYSUt1ppFe8oPKcnWGHCg11VLKTY36V9jfyQvswjdh",
"delegate_pay_rate": 255,
"meta_data": {
"type": "public_account",
"data": ""
}
}
},{
"type": "withdraw_op_type",
"data": {
"balance_id": "BTSX6nhkTeg1qnBbCHtJ4q8GUrBU9Sq2fTS23",
"amount": 50,
"claim_input_data": ""
}
}
]
}
)";
auto tx = fc::json::from_string(tx_json).as<signed_transaction>();
auto priv = wif_to_key("[edited]");
fc::sha256 chain_id;
fc::from_variant("75c11a81b7670bbaa721cc603eadb2313756f94a3bcbb9928e9101432701ac5f", chain_id);
auto signature = priv->sign_compact( tx.digest(chain_id) );
tx.signatures.push_back(signature);
std::cout << fc::json::to_pretty_string(tx) << std::endl;
vector<char> data;
data = fc::raw::pack(tx);
std::cout << fc::to_hex(data) << std::endl;
return 0;
}
-
Good work!