Example #1
0
def set_quorum_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(bob['id']) \
        .setAccountQuorum(alice['id'], 2) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(bob['key']).finish()
Example #2
0
def create_asset_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .createAsset('coin', 'test', 2) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #3
0
def remove_signatory_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .removeSignatory(alice['id'], alice['key'].publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
def create_account_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .createAccount('bob', 'test', bob['key'].publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #5
0
def detach_role_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .detachRole(admin['id'], 'test_role') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #6
0
def grant_can_remove_my_signatory_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .grantPermission(bob['id'], iroha.Grantable_kRemoveMySignatory) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
def revoke_can_set_my_account_detail_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .revokePermission(bob['id'], iroha.Grantable_kSetMyAccountDetail) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #8
0
def add_asset_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .addAssetQuantity('coin#test', '5000.99') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #9
0
def set_account_detail_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .setAccountDetail(admin['id'], 'fav_color', 'red') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #10
0
def transfer_asset_tx():
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .transferAsset(alice['id'], bob['id'], 'coin#test', 'transfer to Bob', '60.00') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #11
0
def create_domain_tx():
    # 'test_role' was created in genesis transaction
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .createDomain('another-domain', 'test_role') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #12
0
def get_asset_query():
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(1) \
        .creatorAccountId(alice['id']) \
        .getAssetInfo('coin#test') \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #13
0
def account_asset_transactions_query():
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(1) \
        .creatorAccountId(alice['id']) \
        .getAccountAssetTransactions(admin['id'], 'coin#first') \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #14
0
def set_quorum_tx():
    # Quourum cannot be greater than amount of keys linked to an account
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .setAccountQuorum(alice['id'], 2) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #15
0
def add_peer_tx():
    peer_key = iroha.ModelCrypto().generateKeypair()
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .addPeer('192.168.10.10:50541', peer_key.publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #16
0
def get_role_permissions_query():
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(2) \
        .creatorAccountId(alice['id']) \
        .getRolePermissions('admin_role') \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #17
0
def add_signatory_tx():
    extra_key = iroha.ModelCrypto().generateKeypair()
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .addSignatory(alice['id'], extra_key.publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #18
0
def get_system_roles_query():
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(1) \
        .creatorAccountId(alice['id']) \
        .getRoles() \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #19
0
def account_detail_query():
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(1) \
        .creatorAccountId(alice['id']) \
        .getAccountDetail(admin['id']) \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #20
0
def grant_can_remove_my_signatory_tx():
    extra_key = iroha.ModelCrypto().generateKeypair()
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .grantPermission(bob['id'], iroha.Grantable_kRemoveMySignatory) \
        .addSignatory(alice['id'], extra_key.publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #21
0
def admin_action_2_tx():
    global admin_tx2_hash_blob
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(admin['id']) \
        .setAccountDetail(admin['id'], 'hyperledger', 'iroha') \
        .build()
    admin_tx2_hash_blob = tx.hash().blob()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(admin['key']).finish()
Example #22
0
def alice_action_2_tx():
    global alice_tx2_hash_blob
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .addAssetQuantity('coin#first', '600.30') \
        .build()
    alice_tx2_hash_blob = tx.hash().blob()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #23
0
def alice_action_1_tx():
    global alice_tx1_hash
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .createAsset('coin', 'first', 2) \
        .build()
    alice_tx1_hash = tx.hash()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #24
0
def append_role_tx():
    # Note that you can append only that role that has
    # lesser or the same set of permissions as transaction creator.
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .appendRole(bob['id'], 'second_role') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #25
0
def create_role_tx():
    # You can pick only those permissions that
    # already belong to account of transaction creator.
    role_permissions = iroha.RolePermissionSet([iroha.Role_kCreateDomain])
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(alice['id']) \
        .createRole('newrole', role_permissions) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #26
0
def transactions_query():
    hashes = iroha.HashVector()
    hashes.append(alice_tx1_hash)
    hashes.append(iroha.Hash(iroha.Blob(alice_tx2_hash_blob)))
    tx = iroha.ModelQueryBuilder() \
        .createdTime(commons.now()) \
        .queryCounter(1) \
        .creatorAccountId(alice['id']) \
        .getTransactions(hashes) \
        .build()
    return iroha.ModelProtoQuery(tx) \
        .signAndAddSignature(alice['key']).finish()
Example #27
0
def genesis_tx():
    test_permissions = iroha.RolePermissionSet([iroha.Role_kGetMyAccount])
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(admin['id']) \
        .addPeer('0.0.0.0:50541', admin['key'].publicKey()) \
        .createRole('admin_role', commons.all_permissions()) \
        .createRole('test_role', test_permissions) \
        .createDomain('test', 'test_role') \
        .createAccount('admin', 'test', admin['key'].publicKey()) \
        .createAccount('alice', 'test', alice['key'].publicKey()) \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(admin['key']).finish()
Example #28
0
def genesis_tx():
    test_permissions = iroha.RolePermissionSet([iroha.Role_kGetDomainAccAstTxs])
    tx = iroha.ModelTransactionBuilder() \
        .createdTime(commons.now()) \
        .creatorAccountId(admin['id']) \
        .addPeer('0.0.0.0:50541', admin['key'].publicKey()) \
        .createRole('admin_role', commons.all_permissions()) \
        .createRole('test_role', test_permissions) \
        .createDomain('test', 'test_role') \
        .createAccount('admin', 'test', admin['key'].publicKey()) \
        .createAccount('alice', 'test', alice['key'].publicKey()) \
        .createAsset('coin', 'test', 2) \
        .addAssetQuantity('coin#test', '500.69') \
        .transferAsset(admin['id'], alice['id'], 'coin#test', 'top up', '10.00') \
        .build()
    return iroha.ModelProtoTransaction(tx) \
        .signAndAddSignature(admin['key']).finish()
Example #29
0
def download_album_photos(album, photos):
    if not album or not photos:
        return
    dirname = os.path.join(OUTPUT, album['id'])
    done_file = os.path.join(dirname, 'done.0')
    if os.path.exists(done_file):
        print('跳过已存在的相册[{0}]'.format(album['title'].encode('utf8')))
        return
    print('开始下载相册[{0}]的图片'.format(album['title'].encode('utf8')))
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    for photo in photos:
        name = photo.rsplit('/', 1)[1]
        imgfile = os.path.join(dirname, name)
        if not os.path.exists(imgfile):
            u, n = commons.download_file(photo, imgfile)
            if n:
                print('完成下载 {0}'.format(photo))
    with open(done_file, 'w') as f:
        f.write(commons.now())
    print('相册[{0}]的图片下载完成'.format(album['title'].encode('utf8')))