def tx(self, account, cosigner_keypair, weight):

        builder = Builder(address=account.get_info()['account_id'])

        builder.append_set_options_op(
            high_threshold=10,
            low_threshold=1,
            master_weight=10,
            med_threshold=1,
            signer_weight=weight,
            signer_address=cosigner_keypair.address().decode(),
            signer_type='ed25519PublicKey')

        return builder.gen_te()
    def call(self):
        keypair = self.keypair()

        builder = Builder(address=keypair.address().decode(),
                          sequence=self.random_sequence(),
                          secret=keypair.seed())

        builder.sign()

        builder.add_memo(self.memo())
        builder.add_time_bounds(self.build_time_bounds())

        builder.append_payment_op(source=Keypair.random(),
                                  destination=keypair.address().decode(),
                                  amount='0.000001')
        builder.sign()

        te = builder.gen_te()

        return te.xdr()
    def tx(self, account, asset):
        builder = Builder(address=account['account_id'])

        builder.append_op(ChangeTrust(opts={'asset': asset}))

        return builder.gen_te()
示例#4
0
tau_unix = int(time.mktime(tau.timetuple()))
tau_plus_delta = tau + datetime.timedelta(seconds=DELTA)
tau_plus_delta_unix = int(time.mktime(tau_plus_delta.timetuple()))
tx_timebound = TimeBounds(
    minTime=tau_unix, maxTime=tau_plus_delta_unix)
counter_tx_timebound = TimeBounds(minTime=0, maxTime=tau_unix)

builder_t_1_1 = Builder(secret=kp_a_1_seed,
                        sequence=starting_sequence_a_1+1)
builder_t_1_1.append_payment_op(
    kp_alice.address().decode(), PRIZE, 'XLM')
builder_t_1_1.append_payment_op(
    kp_carol.address().decode(), PAWN, 'XLM')
builder_t_1_1.add_time_bounds(tx_timebound)
t_1_1 = builder_t_1_1.gen_tx()
hash_t_1_1 = builder_t_1_1.gen_te().hash_meta()

builder_t_1_2 = Builder(secret=kp_a_1_seed,
                        sequence=starting_sequence_a_1+1)
builder_t_1_2.append_payment_op(
    kp_bob.address().decode(), COUNTERPRIZE, 'XLM')
builder_t_1_2.add_time_bounds(counter_tx_timebound)
t_1_2 = builder_t_1_2.gen_tx()
hash_t_1_2 = builder_t_1_2.gen_te().hash_meta()

builder_t_2_2 = Builder(secret=kp_a_2_seed,
                        sequence=starting_sequence_a_2+1)
builder_t_2_2.append_payment_op(
    kp_bob.address().decode(), PRIZE, 'XLM')
builder_t_2_2.append_payment_op(
    kp_carol.address().decode(), PAWN, 'XLM')
    def build_te(self):
        builder = Builder(address=self.user_account.get_info()['account_id'])
        te = builder.gen_te()

        return te
示例#6
0
def genptxs(
	systemdb,
	timestamp):
	"""generates contract ptxs 1-3 given systemdb, including a contract manifest
		in production, will add ptxs will be hosted along with manifest on e.g. IPFS

	"""

	q = Query()
	a_sk = systemdb.search(q.name == 'Contract')[0]['sk']
	a_pk = systemdb.search(q.name == 'Contract')[0]['pk']
	pr_pk = systemdb.search(q.name == 'Printer')[0]['pk']
	pi_pk = systemdb.search(q.name == 'Pipe')[0]['pk']

	UND = systemdb.search(q.type == 'manifest')[0]['UND']
	UND_pk = systemdb.search(q.type == 'manifest')[0]['UND_source']
	QUO = systemdb.search(q.type == 'manifest')[0]['QUO']
	QUO_pk = systemdb.search(q.type == 'manifest')[0]['QUO_source']

	strike = systemdb.search(q.type == 'manifest')[0]['strike']
	size = systemdb.search(q.type == 'manifest')[0]['size']

	address = Address(address=a_pk, network='TESTNET')
	address.get()

	####2 PREAUTH TX ONE #####

	b = Builder(
		secret = str(a_sk), 
		horizon_uri = 'https://horizon.stellar.org',
		network = 'TESTNET', 
		sequence = int(address.sequence)+3)
	"""seq incremented by two bc acct will need to add hash signer, data entry, and lock
	"""

	strikeXsize = str(int(strike)*int(size))

	b.append_payment_op(pr_pk, '0.5', 'OCA', pr_pk)
	if QUO_pk == None:
		b.append_payment_op(pi_pk, strikeXsize, QUO, asset_issuer=None)
	else:
		b.append_payment_op(pi_pk, strikeXsize, QUO, QUO_pk)


	b.append_manage_offer_op('SPA', pr_pk, 'OCA', pr_pk, '0.0000001', '5000000', offer_id=0)
	b.append_manage_offer_op('GTA', pr_pk, 'SPA', pr_pk, '1', '0.0000001', offer_id=0)
	price = str(float(1)/int(size))
	b.append_manage_offer_op(UND, UND_pk, 'GTA', pr_pk, str(size), price, offer_id=0)

	envelope1 = b.gen_te()
	hashish1 = envelope1.hash_meta()
	xdr1 = b.gen_xdr()

	systemdb.insert({
		'type': 'ptx',
		'name': 'ptx1',
		'xdr': xdr1
		})

	####2 PREAUTH TX TWO #####

	b2 = Builder(
		secret = a_sk, 
		horizon_uri ='https://horizon.stellar.org',
		network = 'TESTNET', 
		sequence = int(address.sequence)+3)

	b2.append_payment_op(pi_pk, str(strike), UND, UND_pk)
	b2.append_set_options_op(master_weight=1, low_threshold=0, med_threshold=0, high_threshold=0)

	envelope2 = b2.gen_te()
	hashish2 = envelope2.hash_meta()
	xdr2 = b2.gen_xdr()

	systemdb.insert({
		'type': 'ptx',
		'name': 'ptx2',
		'xdr': xdr2
		})

	####2 PREAUTH TX THREE #####

	b3 = Builder(
		secret = a_sk, 
		horizon_uri ='https://horizon.stellar.org',
		network = 'TESTNET', 
		sequence = int(address.sequence)+4)

	b3.append_set_options_op(master_weight=1, low_threshold=0, med_threshold=0, high_threshold=0)

	envelope3 = b3.gen_te()
	hashish3 = envelope3.hash_meta()
	xdr3 = b3.gen_xdr()

	systemdb.insert({
		'type': 'ptx',
		'name': 'ptx3',
		'xdr': xdr3
		})

 	bX = Builder(secret = a_sk, network='TESTNET')
	bX.append_pre_auth_tx_signer(hashish1, 1, source=None)
	bX.append_pre_auth_tx_signer(hashish2, 1, source=None)
	bX.append_pre_auth_tx_signer(hashish3, 1, source=None)
	bX.sign()
	print bX.submit()