1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 19:38:09 +00:00

altcoin: Capricoin support tests and minor trezorctl addition. (#325)

This commit is contained in:
Tibor Arpas 2018-10-24 15:05:59 +02:00 committed by matejcik
parent f78885af5a
commit e9b540e6b6
6 changed files with 176 additions and 1 deletions

View File

@ -879,9 +879,12 @@ def sign_tx(connect, coin):
tx_version = click.prompt("Transaction version", type=int, default=2) tx_version = click.prompt("Transaction version", type=int, default=2)
tx_locktime = click.prompt("Transaction locktime", type=int, default=0) tx_locktime = click.prompt("Transaction locktime", type=int, default=0)
tx_timestamp = click.prompt(
"Transaction timestamp (Capricoin)", type=int, default=None
)
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
client, coin, inputs, outputs, tx_version, tx_locktime client, coin, inputs, outputs, tx_version, tx_locktime, timestamp=tx_timestamp
) )
client.close() client.close()

View File

@ -92,6 +92,7 @@ def sign_tx(
overwintered=None, overwintered=None,
version_group_id=None, version_group_id=None,
debug_processor=None, debug_processor=None,
timestamp=None,
): ):
# start = time.time() # start = time.time()
txes = client._prepare_sign_tx(inputs, outputs) txes = client._prepare_sign_tx(inputs, outputs)
@ -111,6 +112,8 @@ def sign_tx(
tx.overwintered = overwintered tx.overwintered = overwintered
if version_group_id is not None: if version_group_id is not None:
tx.version_group_id = version_group_id tx.version_group_id = version_group_id
if timestamp is not None:
tx.timestamp = timestamp
res = client.call(tx) res = client.call(tx)
# Prepare structure for signatures # Prepare structure for signatures
@ -155,6 +158,7 @@ def sign_tx(
msg.version = current_tx.version msg.version = current_tx.version
msg.lock_time = current_tx.lock_time msg.lock_time = current_tx.lock_time
msg.inputs_cnt = len(current_tx.inputs) msg.inputs_cnt = len(current_tx.inputs)
msg.timestamp = current_tx.timestamp
if res.details.tx_hash: if res.details.tx_hash:
msg.outputs_cnt = len(current_tx.bin_outputs) msg.outputs_cnt = len(current_tx.bin_outputs)
else: else:

View File

@ -0,0 +1,75 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2018 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import btc, coins, messages as proto
from trezorlib.tools import parse_path
from .common import TrezorTest
TXHASH_3bf506 = bytes.fromhex(
"3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f"
)
TXHASH_f3a6e6 = bytes.fromhex(
"f3a6e6411f1b2dffd76d2729bae8e056f8f9ecf8996d3f428e75a6f23f2c5e8c"
)
@pytest.mark.xfail
@pytest.mark.capricoin
class TestMsgSigntx(TrezorTest):
def test_timestamp_included(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(coins.tx_api["Capricoin"])
# tx: 3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f
# input 0: 0.01 CPC
# tx: f3a6e6411f1b2dffd76d2729bae8e056f8f9ecf8996d3f428e75a6f23f2c5e8c
# input 0: 0.02 CPC
inp1 = proto.TxInputType(
address_n=parse_path("m/44'/289'/0'/0/0"),
prev_hash=TXHASH_3bf506,
prev_index=0,
)
inp2 = proto.TxInputType(
address_n=parse_path("m/44'/289'/0'/0/0"),
prev_hash=TXHASH_f3a6e6,
prev_index=1,
)
out1 = proto.TxOutputType(
address="CUGi8RGPWxbHM6FxF4eMEfqmQ6Bs5VjCdr",
amount=3000000 - 20000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with self.client:
timestamp_signatures, timestamp_tx = btc.sign_tx(
self.client,
"Capricoin",
[inp1, inp2],
[out1],
version=1,
timestamp=0x5BCF5C66,
)
# Accepted by network https://insight.capricoin.org/tx/1bf227e6e24fe1f8ac98849fe06a2c5b77762e906fcf7e82787675f7f3a10bb8
accepted_txhex = "01000000665ccf5b025f23e76913e3e53bc20a6c5db1607cc162d197c7dd791689da4ee81cc806f53b000000006b483045022100fce7ccbeb9524f36d118ebcfebcb133a05c236c4478e2051cfd5c9632920aee602206921b7be1a81f30cce3d8e7dba4597fc16a2761c42321c49d65eeacdfe3781250121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff8c5e2c3ff2a6758e423f6d99f8ecf9f856e0e8ba29276dd7ff2d1b1f41e6a6f3010000006a473044022015d967166fe9f89fbed8747328b1c4658aa1d7163e731c5fd5908feafe08e9a6022028af30801098418bd298cc60b143c52c48466f5791256721304b6eba4fdf0b3c0121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff01a0782d00000000001976a914818437acfd15780debd31f3fd21d4ca678bb36d188ac00000000"
assert timestamp_tx.hex() == accepted_txhex

View File

@ -0,0 +1,45 @@
{
"txid" : "3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f",
"version" : 1,
"time" : 1540315430,
"locktime" : 0,
"vin" : [
{
"txid" : "915340ecc7466d287596f1f5b1fa0c1fa78c5b76ede0dff978fd6a1ca31eee24",
"vout" : 0,
"scriptSig" : {
"asm" : "3045022100c48a9689e2fc28c354d567390c15b94b86923f3c94b7674a69c20113cc83d16102202d0b12d451a4c28fd6c092bb46bf64e242a0c5898420e59c8d7799261ae449a901 03b3a1b0304d81f5a8366281c9a5516d8b3f1cfe6a720f3bf7a222e3a46a87f2c3",
"hex" : "483045022100c48a9689e2fc28c354d567390c15b94b86923f3c94b7674a69c20113cc83d16102202d0b12d451a4c28fd6c092bb46bf64e242a0c5898420e59c8d7799261ae449a9012103b3a1b0304d81f5a8366281c9a5516d8b3f1cfe6a720f3bf7a222e3a46a87f2c3"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.01000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 369df3cc0eb7acd7f0e0491a225a2ddad5ce3d4a OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914369df3cc0eb7acd7f0e0491a225a2ddad5ce3d4a88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"CMSgH7wq4kV9ogmSPB5rBmPceQJy3oA9Bu"
]
}
},
{
"value" : 0.49452200,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 52546e612e890e3028ee4b3d8b6333bb6912bfae OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91452546e612e890e3028ee4b3d8b6333bb6912bfae88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"CPyD89mKLJEi5NESHfxbAYZGe8F9x61YNk"
]
}
}
]
}

View File

@ -0,0 +1,45 @@
{
"txid" : "f3a6e6411f1b2dffd76d2729bae8e056f8f9ecf8996d3f428e75a6f23f2c5e8c",
"version" : 1,
"time" : 1540315682,
"locktime" : 0,
"vin" : [
{
"txid" : "3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f",
"vout" : 1,
"scriptSig" : {
"asm" : "3044022064cc095beb149568f08d4f0b42fea2c41d5864a7c71e5770467c6e07dc03bc5702201ff7f2654ad7a09efca5483b7a7584fffccda9f79b6e9cdb77e407e66e07f71e01 03e8d2aee7293fa37e85692b9f41d2fda52787f10cbe486642a0a7543cc478160b",
"hex" : "473044022064cc095beb149568f08d4f0b42fea2c41d5864a7c71e5770467c6e07dc03bc5702201ff7f2654ad7a09efca5483b7a7584fffccda9f79b6e9cdb77e407e66e07f71e012103e8d2aee7293fa37e85692b9f41d2fda52787f10cbe486642a0a7543cc478160b"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.47440250,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 83259afffb250f9dee12cd0240956ae5e0f351e0 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91483259afffb250f9dee12cd0240956ae5e0f351e088ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"CURL93YyedCm2qwfJ1Jtsk8JnrQHavVehe"
]
}
},
{
"value" : 0.02000000,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 369df3cc0eb7acd7f0e0491a225a2ddad5ce3d4a OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914369df3cc0eb7acd7f0e0491a225a2ddad5ce3d4a88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"CMSgH7wq4kV9ogmSPB5rBmPceQJy3oA9Bu"
]
}
}
]
}

View File

@ -94,6 +94,9 @@ class TxApiInsight(TxApi):
t.version = data["version"] t.version = data["version"]
t.lock_time = data.get("locktime") t.lock_time = data.get("locktime")
if self.network == "insight_capricoin":
t.timestamp = data["time"]
if self.decred: if self.decred:
t.expiry = data["expiry"] t.expiry = data["expiry"]