Beispiel #1
0
def parse_tx_file(infile):

    err_fmt = 'Invalid {} in transaction file'
    tx_data = get_lines_from_file(infile)

    try:
        err_str = 'number of lines'
        assert len(tx_data) in (4, 5)
        if len(tx_data) == 5:
            metadata, tx_hex, inputs, outputs, comment = tx_data
        elif len(tx_data) == 4:
            metadata, tx_hex, inputs, outputs = tx_data
            comment = ''
        err_str = 'metadata'
        assert len(metadata.split()) == 3
        err_str = 'hex data'
        unhexlify(tx_hex)
        err_str = 'inputs data'
        inputs = eval(inputs)
        err_str = 'btc-to-mmgen address map data'
        outputs = eval(outputs)
        if comment:
            from mmgen.bitcoin import b58decode
            comment = b58decode(comment)
            if comment == False:
                err_str = 'encoded comment (not base58)'
            else:
                err_str = 'comment'
                comment = MMGenTXLabel(comment)
    except:
        die(2, err_fmt.format(err_str))
    else:
        return metadata.split(), tx_hex, inputs, outputs, comment
Beispiel #2
0
def parse_tx_file(infile):

	err_fmt = 'Invalid {} in transaction file'
	tx_data = get_lines_from_file(infile)

	try:
		err_str = 'number of lines'
		assert len(tx_data) in (4,5)
		if len(tx_data) == 5:
			metadata,tx_hex,inputs,outputs,comment = tx_data
		elif len(tx_data) == 4:
			metadata,tx_hex,inputs,outputs = tx_data
			comment = ''
		err_str = 'metadata'
		assert len(metadata.split()) == 3
		err_str = 'hex data'
		unhexlify(tx_hex)
		err_str = 'inputs data'
		inputs = eval(inputs)
		err_str = 'btc-to-mmgen address map data'
		outputs = eval(outputs)
		if comment:
			from mmgen.bitcoin import b58decode
			comment = b58decode(comment)
			if comment == False:
				err_str = 'encoded comment (not base58)'
			else:
				err_str = 'comment'
				comment = MMGenTXLabel(comment)
	except:
		die(2,err_fmt.format(err_str))
	else:
		return metadata.split(),tx_hex,inputs,outputs,comment
Beispiel #3
0
def parse_tx_file(infile):
    from ast import literal_eval

    def eval_io_data(raw_data, desc):
        import re
        d = literal_eval(re.sub(r"[A-Za-z]+?\(('.+?')\)", r'\1', raw_data))
        assert type(d) == list, '{} data not a list!'.format(desc)
        assert len(d), 'no {}!'.format(desc)
        for e in d:
            e['amount'] = g.proto.coin_amt(e['amount'])
        return d

    err_fmt = 'Invalid {} in transaction file'
    tx_data = get_lines_from_file(infile)

    try:
        err_str = 'number of lines'
        assert len(tx_data) in (4, 5)
        if len(tx_data) == 5:
            metadata, tx_hex, inputs, outputs, comment = tx_data
        elif len(tx_data) == 4:
            metadata, tx_hex, inputs, outputs = tx_data
            comment = ''
        err_str = 'metadata'
        assert len(metadata.split()) == 3
        err_str = 'hex data'
        unhexlify(tx_hex)
        err_str = 'inputs data'
        inputs = eval_io_data(inputs, 'inputs')
        err_str = 'btc-to-mmgen address map data'
        outputs = literal_eval(outputs)
        if comment:
            from mmgen.bitcoin import b58decode
            comment = b58decode(comment)
            if comment == False:
                err_str = 'encoded comment (not base58)'
            else:
                err_str = 'comment'
                comment = MMGenTXLabel(comment)
    except:
        die(2, err_fmt.format(err_str))
    else:
        return metadata.split(), tx_hex, inputs, outputs, comment
Beispiel #4
0
def parse_tx_file(tx_data,infile):

	err_str,err_fmt = "","Invalid %s in transaction file"

	if len(tx_data) == 5:
		metadata,tx_hex,inputs_data,outputs_data,comment = tx_data
	elif len(tx_data) == 4:
		metadata,tx_hex,inputs_data,outputs_data = tx_data
		comment = ""
	else:
		err_str = "number of lines"

	if not err_str:
		if len(metadata.split()) != 3:
			err_str = "metadata"
		else:
			try: unhexlify(tx_hex)
			except: err_str = "hex data"
			else:
				try: inputs_data = eval(inputs_data)
				except: err_str = "inputs data"
				else:
					try: outputs_data = eval(outputs_data)
					except: err_str = "mmgen-to-btc address map data"
					else:
						if comment:
							from mmgen.bitcoin import b58decode
							comment = b58decode(comment)
							if comment == False:
								err_str = "encoded comment (not base58)"
							else:
								if is_valid_tx_comment(comment):
									comment = comment.decode("utf8")
								else:
									err_str = "comment"

	if err_str:
		msg(err_fmt % err_str)
		sys.exit(2)
	else:
		return metadata.split(),tx_hex,inputs_data,outputs_data,comment
Beispiel #5
0
def b58randenc():
	r = get_random(32)
	enc = bitcoin.b58encode(r)
	dec = bitcoin.b58decode(enc)
	print_convert_results(r,enc,dec,"str")
Beispiel #6
0
def strtob58(s):
	enc = bitcoin.b58encode(s)
	dec = bitcoin.b58decode(enc)
	print_convert_results(s,enc,dec,"str")