コード例 #1
0
ファイル: zap_foil.py プロジェクト: djpnewton/zap_foil
def sweep_run(args):
    pw.setOnline()
    # check recipient is a valid address
    if not pw.validateAddress(args.recipient):
        print(f"ERROR: {args.recipient} is not a valid address")
        sys.exit(EXIT_INVALID_RECIPIENT)
    recipient = pw.Address(args.recipient)

    # sweep expired foils
    asset = pw.Asset(args.assetid)
    asset_fee = get_asset_fee(args.assetid)
    date = time.time()
    foils = Foil.get_batches_between(db_session, args.batch_start, args.batch_end)
    for foil in foils:
        if args.ignore_expiry or foil.expiry and date >= foil.expiry:
            addr = pw.Address(seed=foil.seed)
            balance = addr.balance(assetId=args.assetid)
            if balance == 0:
                print(f"Skipping {foil.batch} {addr.address}, balance is 0")
                continue
            result = addr.sendAsset(recipient, asset, balance - asset_fee, \
                feeAsset=asset, txFee=asset_fee)
            print(result)
            print(f"Swept {foil.batch} {addr.address}, txid {result['id']}")
        else:
            print(f"Skipping {foil.batch} {addr.address}, not yet expired")
コード例 #2
0
    def deploy(self):
        if NETWORKS[self.contract.network.name]['is_free']:
            pw.setNode(node='https://{addr}'.format(
                addr=NETWORKS[self.contract.network.name]['host']),
                       chain=NETWORKS[self.contract.network.name]['type'])
        else:
            pw.setNode(node='https://{addr}'.format(
                addr=NETWORKS[self.contract.network.name]['host']),
                       chain=NETWORKS[self.contract.network.name]['type'])
        pw.setOnline()

        deploy_address = pw.Address(
            privateKey=NETWORKS[self.contract.network.name]['private_key'])
        pubKey, privKey, address = create_waves_privkey()
        created_address = {
            'publicKey': pubKey,
            'privateKey': privKey,
            'address': address
        }
        contract_address = pw.Address(privateKey=privKey)
        print('account created', pubKey, privKey, address, flush=True)
        sending = sign_send_waves(deploy_address, created_address['address'],
                                  110000000)
        #sending = deploy_address.sendWaves(contract_address, 110000000)
        print('sending', sending, flush=True)
        time.sleep(30)
        asset_id = ''
        if not self.reused_token:
            token_params = {
                'name': self.token_short_name,
                'description': self.token_description,
                'total_supply': self.total_supply,
                'decimals': self.decimals
            }
            token_tx = issue_asset_waves(token_params, created_address)
            print('token tx', token_tx, flush=True)
            asset_id = token_tx['assetId']

        token_address = self.asset_id if self.reused_token else asset_id
        self.compile(asset_id=token_address)

        script_trx = set_script_waves(self.ride_contract.source_code,
                                      created_address)

        # try:
        #     trx = contract_address.setScript(
        #         self.ride_contract.source_code,
        #     txFee=1000000,
        #     timestamp=0
        #     )
        # except KeyError:
        #     pw.setOffline()
        #     trx = contract_address.setScript(
        #         self.ride_contract.source_code,
        #     txFee=1000000,
        #     timestamp=0
        #     )
        #     print('setScript trx not broadcasted', token_trx, flush=True)
        #     pw.setOffline()
        print('trx', script_trx, flush=True)
        if not self.asset_id:
            self.asset_id = token_address
            self.save()
        # self.ride_contract.address = address
        self.ride_contract.tx_hash = script_trx['id']
        self.ride_contract.address = script_trx['sender']
        self.ride_contract.bytecode = script_trx['script']
        self.ride_contract.save()
        self.contract.state = 'ACTIVE'
        self.contract.save()
        take_off_blocking(self.contract.network.name)
コード例 #3
0
def send_data_transaction(seed, data):
    adr = pw.Address(seed=seed)
    pw.setOnline()
    adr.dataTransaction()
コード例 #4
0
import pywaves as pw

pw.setNode(node='https://testnode2.wavesnodes.com', chain='testnet')
script = 'match tx { \n' + \
'  case _ => true\n' + \
'}'
myAddress = pw.Address(
    seed=
    'kind expire cream settle tribe despair act endorse boss material lonely piano advice laundry visa'
)
pw.setOnline()
data = [{'type': 'string', 'key': 'test', 'value': 'testval'}]

print(myAddress.dataTransaction(data))


def send_data_transaction(seed, data):
    adr = pw.Address(seed=seed)
    pw.setOnline()
    adr.dataTransaction()