关系类交易

设置关系

在井通系统中,用户可以建立不同账号之间的关联,即关系,从而实现某些现实世界中的资产转移模式。

目前支持的关系有授权(autorize)和冻结(freeze)两种。

授权(autorize)是将用户账号中的电子资产用于另一账号支付的情况。如账号A授权账号B 100积分M,那么在账号B支付账号C积分M时,如果余额不足,账号A将自动支付100以内的积分M给账户C。

冻结(freeze)是冻结本账号中的电子资产给对方账号。如账号A冻结100积分M给账户B, 那么账号A不能将100积分支付给其他账号(包括账号B),直到账号B解冻账号A的100积分才行。 解冻过程不能由本账号进行,而是通过对方账号进行。冻结的效果类似保证金。

授权和冻结的额度不能是SWT。

设置关系是通过RelationOperation来进行的。

解除关系是通过RemoveRelationOperation来进行的。

参数 类型 说明
type String 关系种类,authorize和freeze
counterparty String 关系被动方的井通地址
amount Object 关系的额度

Java Example

// 1. prepare wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. construct setSettings operation
RelationOperation op = new RelationOperation(wallet1);

op.setType("authorize");//default is null
op.setCounterparty("j12300…n");//Another wallet address

Amount in_amt = new Amount(100.0, "CNY", "janxMdr...GewMMeHa9f");

op.setAmount(in_amt);//An amount object

op.submit(rls);
// 3. submit RelationOperation
op.submit(new RelationListener() {
    @override
    public void onComplete(result) {
        // process result
    };
});

Python Example

# 1. prepare wallet
wallet1 = Wallet("snqFcH......pQYzxEEbW");


# 2. construct setSettings operation

op = RelationOperation(wallet1);
op.setCounterparty("j12300…n");#default is null
op.setType("authorize");#default is null

Amount in_amt = new Amount(100.0, "CNY", "janxMdr...GewMMeHa9f");
op.setAmount(in_amt);#An amount object


# 3. submit RelationOperation
op.submit(callback);

PHP Example

// 1. prepare wallet
$wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. construct Relation operation
$op = new RelationOperation(wallet1);

$op.setCounterparty ("jnYcyWcn......z62iMQSfaSXUx");

$amount = new Amount(100.0, "CNY", "janxMdr...GewMMeHa9f");
$op.setAmount($amount);
$op.setType("authorize");

// 3. submit RelationOperation
$op.submit('call_back_func');

Node.JS Example

// 1. prepare wallet
var wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. construct Relation Operation
var op = new RelationOperation (wallet1);

op. setCounterparty ("jnYcyWcn......z62iMQSfaSXUx");
var amount = new Amount(1.0, "CNY", "janxMdr...GewMMeHa9f");
op.setAmount(amount);
op.setType("authorize");

// 3. submit RelationOperation
op.submit(function(err, data) {
    // process result
});

取消关系

解除关系是通过RemoveRelationOperation来进行的。

授权(autorize)是将用户账号中的电子资产用于另一账号支付的情况。如账号A授权账号B 100积分M,那么在账号B支付账号C积分M时,如果余额不足,账号A将自动支付100以内的积分M给账户C。 解除授权关系由本账号进行。

冻结(freeze)是冻结本账号中的电子资产给对方账号。如账号A冻结100积分M给账户B, 那么账号A不能将100积分支付给其他账号(包括账号B),直到账号B解冻账号A的100积分才行。 解冻过程不能由本账号进行,而是通过对方账号进行。冻结的效果类似保证金。

授权和冻结的额度不能是SWT。

Java Example

// 1. prepare wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. Construct RemoveRelationOperation
RemoveRelationOperation op = new RemoveRelationOperation (wallet1);

op.setType("authorize");//default is null
op.setCounterparty("j12300…n");//Another wallet address

Amount in_amt = new Amount(1.0, "CNY", " janxMdr...GewMMeHa9f");

op.setAmount(in_amt);//An amount object

op.submit(rls);

// 3. submit RemoveRelationOperation
op.submit(new RemoveRelationListener() {
    @override
    public void onComplete(result) {
        // process result
    };
});

Python Example

# 1. prepare wallet
wallet1 = Wallet("snqFcH......pQYzxEEbW");

# 2. construct RemoveRelationOperation

op = RemoveRelationOperation(wallet1);
op.setCounterparty("j12300…n");#default is null
op.setType("authorize");#default is null

Amount in_amt = new Amount(1.0, "CNY", " janxMdr...GewMMeHa9f");

op.setAmount(in_amt);#An amount object


# 3. submit RemoveRelationOperation
op.submit(callback);

PHP Example

// 1. prepare wallet
$wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. construct RemoveRelationOperation
$op = new RemoveRelationOperation(wallet1);

$op.setCounterparty ("jnYcyWcn......z62iMQSfaSXUx");

$amount = new Amount(1.0, "CNY", " janxMdr...GewMMeHa9f");

$op.setAmount($amount);
$op.setType("authorize");

// 3. submit RemoveRelationOperation
$op.submit('call_back_func');

Node.JS Example

// 1. prepare wallet
var wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// 2. construct RemoveRelationOperation
var op = new RemoveRelationOperation(wallet1);

op. setCounterparty ("jnYcyWcn......z62iMQSfaSXUx");
var amount = new Amount(1.0, "CNY", " janxMdr...GewMMeHa9f");

op.setAmount(amount);
op.setType("authorize");

// 3. submit RemoveRelationOperation
op.submit(function(err, data) {
    // process result
});

查询关系

查询Relation的设置参数直接通过Wallet对象进行。 目前查询关系,type参数不能为空,默认值为authorize。

Java Example

// 1. construct wallet
Wallet wallet = new Wallet("snqFcH......pQYzxEEbW");

// 2. get relations
RelationCollection bc = wallet.getRelation("authorize");

Python Example

# construct source wallet
wallet1 = Wallet("shVC2gdG......gijqk4EsuqDF");

# 2. get relation
bc = wallet.getRelationList("authorize");

PHP Example

// 1. construct wallet
$wallet = new Wallet("snqFcH......pQYzxEEbW");

// 2. get relations
$bc = $wallet->getRelationList("authorize");

Node.JS Example

// 1. construct wallet
var wallet = new Wallet("snqFcH......pQYzxEEbW");

// 2. get relations
wallet.getRelationList("authorize", function(err, data) {
    // process relations
});