ChainApi¶
The ChainApi is responsible to manage a chain in an IL2Node. You will be able to see the list of chains in a node, create a new chain, manage the active IL2Apps in a chain, add permissions and force interlocks. The following example shows how to get an instance of the ChainApi:
from pyil2 import IL2Client
client = IL2Client(
host='https://il2.node:32032/',
cert_filepath='rest.api.pfx',
cert_password='Str0ngPassword'
)
api = client.api('chain')
chains = api.list_chains()
If your are using a certificate with administration privileges, it is possible to create new chains:
new_chain = ChainCreationModel(
name="Chain name",
emergency_closing_key_password="emergencyPassword",
management_key_password="managementPassword",
)
created = api.create_chain(new_chain)
In case you need to permit new apps to this new chain, you can manage the permitted apps in the following way:
permitted_apps = api.add_active_apps(
new_chain.id,
[4, 8]
)
Now lets manage the permissions of the new chain in this node. First we need to get the list of chains in the node and then we can change the permissions a key can have in this chain:
from pyil2.models.keys import KeyDetailsModel
chains = api.list_chains()
key_to_permit = KeyDetailsModel(
name='key.name',
permissions=[
'#2,500,501',
'#1,300,301',
'#5,701',
'#3,601',
'#4',
'#8,2100'
],
purposes=[
'Action',
'Protocol'
],
id='Key!0ink...REDACTED...Ye2o#SHA1',
public_key='PubKey!KPiQ...REDACTED...BAAE#RSA'
)
keys = api.add_keys(
new_chain.id,
keys_to_permit=[key_to_permit]
)
Note
To permit other keys, the certificate must be already imported to the Interlockledger node.
And finally, if you need to force an interlocking in a chain, you will need to follow the steps bellow:
from pyil2.models.record import ForceInterlockModel
interlock = ForceInterlockModel(
target_chain='UHtr...REDACTED...vXRY'
)
response = api.force_interlocking(new_chain, interlock)
The list of methods in the ChainApi are described as follows:
- class pyil2.api.ChainApi(client: IL2Client)¶
Bases:
BaseApi
API class for the chain requests.
- Parameters:
client (
pyil2.IL2Client
) – IL2Client to be used to send requests.
- base_url¶
Base path of the requests.
- Type:
str
- add_active_apps(chain_id: str, apps_to_permit: List[int]) List[int] | ErrorDetailsModel ¶
Get the list os active apps in the chain.
- Parameters:
chain_id (
str
) – Chain ID.- Returns:
Enumerate apps that are currently permitted in this chain.
- Return type:
[
int
]
- add_keys(chain_id: str, keys_to_permit: List[KeyDetailsModel]) List[KeyDetailsModel] | ErrorDetailsModel ¶
Add keys to the permitted list for the chain.
- Parameters:
chain_id (
str
) – Chain ID.keys_to_permit ([
pyil2.models.keys.KeyDetailsModel
]) – List of keys to permitted.
- Returns:
List of key details.
- Return type:
- create_chain(new_chain: ChainCreationModel) ChainCreatedModel | ErrorDetailsModel ¶
Create a new chain.
- Parameters:
model (
pyil2.models.chain.ChainCreationModel
) – Model with the new chain attrbutes.- Returns:
Chain created model.
- Return type:
- force_interlocking(chain_id: str, interlock: ForceInterlockModel) InterlockingRecordModel | ErrorDetailsModel ¶
Forces an interlock on a target chain.
- Parameters:
chain_id (
str
) – Chain ID.interlock (
pyil2.models.record.ForceInterlockModel
) – Force interlock details.
- Returns:
Interlocking details.
- Return type:
- list_active_apps(chain_id: str) List[int] | ErrorDetailsModel ¶
Get the list os active apps in the chain.
- Parameters:
chain_id (
str
) – Chain ID.- Returns:
Enumerate apps that are currently permitted in this chain.
- Return type:
[
int
]
- list_chains() List[ChainIdModel] | ErrorDetailsModel ¶
Get a list of chains in the node.
- Returns:
List of chains in the node.
- Return type:
- list_interlockings(chain_id: str, page: int = 0, size: int = 10, how_many_from_last: int = 0) ListModel[InterlockingRecordModel] | ErrorDetailsModel ¶
Get list of interlocks registered in the chain.
- Parameters:
chain_id (
str
) – Chain ID.page (
int
) – Page to return.size (
int
) – Number of items per page.how_many_from_last (
int
) – How many interlocking records to return. If ommited or 0 returns all.
- Returns:
List of interlocking records.
- Return type:
pyil2.models.base.ListModel
[pyil2.models.record.InterlockingRecordModel
]
- list_keys(chain_id: str) List[KeyDetailsModel] | ErrorDetailsModel ¶
List keys that are currently permitted in the chain.
- Parameters:
chain_id (
str
) – Chain ID.- Returns:
List of key details.
- Return type:
- summary(chain_id: str) ChainSummaryModel | ErrorDetailsModel ¶
Get the chain details by ID.
- Parameters:
chain_id (
str
) – Chain ID.- Returns:
Chain details.
- Return type: