Ejemplo n.º 1
0
def set_account(settype, var1):
    print('set account')
    sa = Builder(CONF['private_key'], network=CONF['network'])
    if settype == 'inflation':
        sa.append_set_options_op(inflation=var1)
    else:
        sa.append_set_options_op(home_domain=var1)
    sa.sign()
    sa.submit()
Ejemplo n.º 2
0
def lock(systemdb, Account):
	q = Query()
	a_sk = systemdb.search(q.name == Account)[0]['sk']
	b = Builder(secret = a_sk, network='TESTNET')

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

	b.sign()

	print b.submit()
    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()
Ejemplo n.º 4
0
 def _add_signer(builder: Builder, deal_address: str, party: str,
                 amount: Decimal):
     """Set permission of parties can signed transaction that generate from joint account"""
     builder.append_set_options_op(source=deal_address,
                                   signer_address=party,
                                   signer_type='ed25519PublicKey',
                                   signer_weight=1)
     builder.append_payment_op(
         source=party,
         destination=deal_address,
         asset_code=settings['ASSET_CODE'],
         asset_issuer=settings['ISSUER'],
         amount=amount,
     )
 def create_token_and_lock_account(self, code, owner_address, metadata):
     # Setup the base transaction
     builder = Builder(
         secret=self.issuer_secret,
         network=self.network
     )
     # Append relevant payment ops
     ipfs_hash = self.create_ipfs_hash(metadata)
     builder.append_manage_data_op('token_ipfs_hash', ipfs_hash)
     builder.append_payment_op(
         owner_address,
         '0.0000001',
         code,
         self.issuer_keypair.address().decode()
     )
     builder.append_set_options_op(master_weight=0)
     builder.sign()
     return builder.submit()
Ejemplo n.º 6
0
def set_multisig(trusted_key):
    print_formatted_text(HTML('<ansiblue>\n### SET MULTISIG ###</ansiblue>\n'))
    print(
        'set multisig will currently make your key a 2 of 2 multisig address')
    print_formatted_text(
        HTML('trusted key is:<ansired>' + trusted_key + '</ansired>'))
    print(
        'it will set med threshold and high to 2 and master weight to 1 so you can use 2 keys for all sending or issuing tokens\n\n'
    )
    b = Builder(CONF['private_key'], network=CONF['network'])
    b.append_set_options_op(master_weight=1,
                            med_threshold=2,
                            high_threshold=2,
                            signer_address=trusted_key,
                            signer_type='ed25519PublicKey',
                            signer_weight=1,
                            source=None)
    b.sign()
    val = b.submit()
    print(val)
    return
Ejemplo n.º 7
0
    def test_builder(self):
        cold_account = self.cold.address().decode()
        hot_account = self.hot.address().decode()

        fund(cold_account)

        cold = Builder(self.cold.seed().decode())

        cold.append_create_account_op(hot_account, 200)

        cold.append_set_options_op(
            inflation_dest=cold_account,
            set_flags=1,
            home_domain='256kw.com',
            master_weight=10,
            low_threshold=5,
        )
        cold.append_trust_op(cold_account, 'BEER', 1000, source=hot_account)
        cold.append_allow_trust_op(hot_account, 'BEER', True)
        # append twice for test
        cold.append_payment_op(hot_account, 50.123, 'BEER', cold_account)
        cold.append_payment_op(hot_account, 50.123, 'BEER', cold_account)

        cold.sign(self.hot.seed().decode())
        try:  # sign twice
            cold.sign(self.hot.seed().decode())
        except SignatureExistError:
            assert True
        except:
            assert False

        cold.sign()
        assert len(cold.te.signatures) == 2
        assert len(cold.ops) == 5

        try:
            response = cold.submit()
            print(response)
        except:
            assert False
Ejemplo n.º 8
0
    def test_builder(self):
        cold_account = self.cold.address().decode()
        hot_account = self.hot.address().decode()

        fund(cold_account)

        cold = Builder(self.cold.seed().decode())

        cold.append_create_account_op(hot_account, 200)

        cold.append_set_options_op(inflation_dest=cold_account, set_flags=1,
                                   home_domain='256kw.com',master_weight=10,
                                   low_threshold=5,)
        cold.append_trust_op(cold_account, 'BEER', 1000, source=hot_account)
        cold.append_allow_trust_op(hot_account,'BEER', True)
        # append twice for test
        cold.append_payment_op(hot_account, 50.123, 'BEER', cold_account)
        cold.append_payment_op(hot_account, 50.123, 'BEER', cold_account)

        cold.sign(self.hot.seed().decode())
        try:  # sign twice
            cold.sign(self.hot.seed().decode())
        except SignatureExistError:
            assert True 
        except:
            assert False

        cold.sign()
        assert len(cold.te.signatures) == 2
        assert len(cold.ops) == 5

        try:
            response = cold.submit()
            print(response)
        except:
            assert False
async def build_generate_escrow_wallet_transaction(
    escrow_address: str,
    transaction_source_address: str,
    creator_address: str,
    destination_address: str,
    provider_address: str,
    cost_per_transaction: Decimal,
    starting_native_asset: Decimal,
    starting_custom_asset: Decimal,
    expiration_date: str = None,
    sequence: str = None,
) -> Tuple[Any, str]:
    '''Building transaction for generating escrow wallet with minimum balance of lumens
        and return unsigned XDR and transaction hash.

        Args:

        * escrow_address: an address of new wallet
        * destination_address: an address of wallet which is target
        * transaction_source_address an address from wallet pool
        * provider_address: an address which provides custom_asset to new wallet
        * creator_address: an address of source wallet which is owner of the transaction.
        * cost_per_transaction: cost for each promotion deals.
        * starting_native_asset: starting amount of XLM.
        * starting_custom_asset: starting amount of custom asset(HOT).
        * expiration_date: a date when escrow address is terminated.
    '''

    builder = Builder(
        address=transaction_source_address,
        horizon=settings['HORIZON_URL'],
        network=settings['PASSPHRASE'],
        sequence=sequence,
    )
    builder.append_create_account_op(source=creator_address,
                                     destination=escrow_address,
                                     starting_balance=starting_native_asset)

    try:
        builder.append_trust_op(
            source=escrow_address,
            destination=settings['ISSUER'],
            code=settings['ASSET_CODE'],
            limit=settings['LIMIT_ASSET'],
        )
    except DecodeError:
        raise web.HTTPBadRequest(
            reason='Parameter escrow_address or issuer address are not valid.')
    except Exception as e:
        msg = str(e)
        raise web.HTTPInternalServerError(reason=msg)

    builder.append_manage_data_op(source=escrow_address,
                                  data_name='creator_address',
                                  data_value=creator_address)
    builder.append_manage_data_op(source=escrow_address,
                                  data_name='destination_address',
                                  data_value=destination_address)
    builder.append_manage_data_op(source=escrow_address,
                                  data_name='provider_address',
                                  data_value=provider_address)

    if expiration_date:
        builder.append_manage_data_op(source=escrow_address,
                                      data_name='expiration_date',
                                      data_value=expiration_date)
    builder.append_manage_data_op(source=escrow_address,
                                  data_name='cost_per_transaction',
                                  data_value=str(cost_per_transaction))

    builder.append_set_options_op(source=escrow_address,
                                  signer_address=creator_address,
                                  signer_type='ed25519PublicKey',
                                  signer_weight=1)
    builder.append_set_options_op(source=escrow_address,
                                  signer_address=provider_address,
                                  signer_type='ed25519PublicKey',
                                  signer_weight=1)
    builder.append_set_options_op(source=escrow_address,
                                  master_weight=0,
                                  low_threshold=2,
                                  med_threshold=2,
                                  high_threshold=2)

    builder.append_payment_op(
        source=provider_address,
        destination=escrow_address,
        asset_code=settings['ASSET_CODE'],
        asset_issuer=settings['ISSUER'],
        amount=starting_custom_asset,
    )

    try:
        xdr = builder.gen_xdr()
    except Exception as e:
        raise web.HTTPBadRequest(
            reason='Bad request, Please ensure parameters are valid.')

    tx_hash = builder.te.hash_meta()

    return xdr.decode(), binascii.hexlify(tx_hash).decode()
Ejemplo n.º 10
0
builder_t_2_2.append_payment_op(
    kp_carol.address().decode(), PAWN, 'XLM')
builder_t_2_2.add_time_bounds(tx_timebound)
t_2_2 = builder_t_2_2.gen_tx()
hash_t_2_2 = builder_t_2_2.gen_te().hash_meta()

builder_t_2_1 = Builder(secret=kp_a_2_seed,
                        sequence=starting_sequence_a_2+1)
builder_t_2_1.append_payment_op(
    kp_alice.address().decode(), COUNTERPRIZE, 'XLM')
builder_t_2_1.add_time_bounds(counter_tx_timebound)
t_2_1 = builder_t_2_1.gen_tx()
hash_t_2_1 = builder_t_2_1.gen_te().hash_meta()

builder_t_1_0 = Builder(secret=kp_a_1_seed)
builder_t_1_0.append_set_options_op(master_weight=255)
builder_t_1_0.append_set_options_op(med_threshold=2)
builder_t_1_0.append_set_options_op(high_threshold=254)
builder_t_1_0.append_pre_auth_tx_signer(hash_t_1_2, 1)
builder_t_1_0.append_pre_auth_tx_signer(hash_t_1_1, 1)
builder_t_1_0.append_hashx_signer(hash_x_a, 1)
builder_t_1_0.append_set_options_op(master_weight=0)
builder_t_1_0.sign()

builder_t_2_0 = Builder(secret=kp_a_2_seed)
builder_t_2_0.append_set_options_op(master_weight=255)
builder_t_2_0.append_set_options_op(med_threshold=2)
builder_t_2_0.append_set_options_op(high_threshold=254)
builder_t_2_0.append_pre_auth_tx_signer(hash_t_2_1, 1)
builder_t_2_0.append_pre_auth_tx_signer(hash_t_2_2, 1)
builder_t_2_0.append_hashx_signer(hash_x_b, 1)
Ejemplo n.º 11
0
async def build_joint_wallet(
    transaction_source_address: str,
    deal_address: str,
    parties: List,
    creator: str,
    starting_xlm: Decimal,
    meta: str = None,
    sequence: str = None,
):
    """Build transaction for create joint wallet, trust HOT and set option signer."""
    def _add_signer(builder: Builder, deal_address: str, party: str,
                    amount: Decimal):
        """Set permission of parties can signed transaction that generate from joint account"""
        builder.append_set_options_op(source=deal_address,
                                      signer_address=party,
                                      signer_type='ed25519PublicKey',
                                      signer_weight=1)
        builder.append_payment_op(
            source=party,
            destination=deal_address,
            asset_code=settings['ASSET_CODE'],
            asset_issuer=settings['ISSUER'],
            amount=amount,
        )

    builder = Builder(
        address=transaction_source_address,
        horizon=settings['HORIZON_URL'],
        network=settings['PASSPHRASE'],
        sequence=sequence,
    )
    builder.append_create_account_op(source=creator,
                                     destination=deal_address,
                                     starting_balance=starting_xlm)
    builder.append_trust_op(source=deal_address,
                            destination=settings['ISSUER'],
                            code=settings['ASSET_CODE'],
                            limit=settings['LIMIT_ASSET'])
    builder.append_set_options_op(source=deal_address,
                                  signer_address=creator,
                                  signer_type='ed25519PublicKey',
                                  signer_weight=1)

    for party in parties:
        _add_signer(builder, deal_address, party['address'], party['amount'])

    if meta and isinstance(meta, dict):
        for key, value in meta.items():
            builder.append_manage_data_op(source=deal_address,
                                          data_name=key,
                                          data_value=value)

    builder.append_manage_data_op(source=deal_address,
                                  data_name='creator_address',
                                  data_value=creator)

    weight = len(parties) + 1
    builder.append_set_options_op(source=deal_address,
                                  master_weight=0,
                                  low_threshold=weight,
                                  med_threshold=weight,
                                  high_threshold=weight)
    xdr = builder.gen_xdr()
    tx_hash = builder.te.hash_meta()

    return xdr.decode(), binascii.hexlify(tx_hash).decode()
Ejemplo n.º 12
0
kp_issuer = Keypair.random()
kp_distrib = Keypair.random()

# Then we need to fund them with testnet's Lumens
bot_url = "https://friendbot.stellar.org"
requests.get(bot_url, params={'addr': kp_issuer.address().decode()})
requests.get(bot_url, params={'addr': kp_distrib.address().decode()})

# And we create a trust line between the distributor and the issuer
# In order to do that, we build a transaction. I'll use the Builder class, for simplicity.
builder = Builder(secret=kp_distrib.seed().decode())
builder.append_trust_op(kp_issuer.address().decode(), sys.argv[1], sys.argv[2], kp_distrib.address().decode())
builder.sign()
builder.submit()

# We finally send these tokens from issuer to distributer
builder = Builder(secret=kp_issuer.seed().decode())
builder.append_payment_op(kp_distrib.address().decode(), sys.argv[2], sys.argv[1], kp_issuer.address().decode())
builder.sign()
builder.submit()

# To make sure there will not be anymore creation of this token, we make it unavailable by setting the permission of the master key to 0, and the minimum permission for any operation to 1
builder = Builder(secret=kp_distrib.seed().decode())
builder.append_set_options_op(master_weight=0, low_threshold=1, med_threshold=1, high_threshold=1)
builder.sign()
builder.submit()

print("Succesfully created "+sys.argv[2]+" "+sys.argv[1]+" tokens. You can access them via the following account :")
print("Address : "+kp_distrib.address().decode())
print("Key : "+kp_distrib.seed().decode())
Ejemplo n.º 13
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()