Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend pkg with delegate/redelegate/unbond and withdraw #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Version 0.1.5 - 2020-06-22
* Add Delegate, Redelegate, unbond and withdraw.

## Version 0.1.4 - 2020-05-15
* Updated dependencies

Expand Down
4 changes: 4 additions & 0 deletions lib/models/transactions/messages/export.dart
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export 'msg_send.dart';
export 'msg_delegate.dart';
export 'msg_undelegate.dart';
export 'msg_redelegate.dart';
export 'msg_withdraw.dart';
32 changes: 32 additions & 0 deletions lib/models/transactions/messages/msg_delegate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:meta/meta.dart';
import 'package:sacco/models/transactions/export.dart';

/// [MsgDelegate] extends [StdMsg] and represents the message that should be
/// used when delegating tokens.
class MsgDelegate extends StdMsg {
/// Bech32 address of the sender.
final String delegator_address;

/// Bech32 address of the recipient.
final String validator_address;

/// Coins that will be sent.
final List<StdCoin> amount;

/// Public constructor.
MsgDelegate({
@required this.delegator_address,
@required this.validator_address,
@required this.amount,
}) : assert(delegator_address != null),
assert(validator_address != null),
assert(amount != null),
super(type: "cosmos-sdk/MsgDelegate", value: Map());

@override
Map<String, dynamic> get value => {
'delegator_address': this.delegator_address,
'validator_address': this.validator_address,
'amount': this.amount.map((coin) => coin.toJson()).toList(),
};
}
37 changes: 37 additions & 0 deletions lib/models/transactions/messages/msg_redelegate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:meta/meta.dart';
import 'package:sacco/models/transactions/export.dart';

/// [MsgBeginRedelegate] extends [StdMsg] and represents the message that should be
/// used when redelegating tokens.
class MsgBeginRedelegate extends StdMsg {
/// Bech32 address of the sender.
final String delegator_address;

/// Bech32 address of the recipient.
final String validator_src_address;

final String validator_dst_address;

/// Coins that will be sent.
final List<StdCoin> amount;

/// Public constructor.
MsgBeginRedelegate({
@required this.delegator_address,
@required this.validator_src_address,
@required this.validator_dst_address,
@required this.amount,
}) : assert(delegator_address != null),
assert(validator_src_address != null),
assert(validator_dst_address != null),
assert(amount != null),
super(type: "cosmos-sdk/MsgBeginRedelegate", value: Map());

@override
Map<String, dynamic> get value => {
'delegator_address': this.delegator_address,
'validator_src_address': this.validator_src_address,
'validator_dst_address': this.validator_dst_address,
'amount': this.amount.map((coin) => coin.toJson()).toList(),
};
}
32 changes: 32 additions & 0 deletions lib/models/transactions/messages/msg_undelegate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:meta/meta.dart';
import 'package:sacco/models/transactions/export.dart';

/// [MsgUndelegate] extends [StdMsg] and represents the message that should be
/// used when undelegating tokens.
class MsgUndelegate extends StdMsg {
/// Bech32 address of the sender.
final String delegator_address;

/// Bech32 address of the recipient.
final String validator_address;

/// Coins that will be sent.
final List<StdCoin> amount;

/// Public constructor.
MsgUndelegate({
@required this.delegator_address,
@required this.validator_address,
@required this.amount,
}) : assert(delegator_address != null),
assert(validator_address != null),
assert(amount != null),
super(type: "cosmos-sdk/MsgUndelegate", value: Map());

@override
Map<String, dynamic> get value => {
'delegator_address': this.delegator_address,
'validator_address': this.validator_address,
'amount': this.amount.map((coin) => coin.toJson()).toList(),
};
}
32 changes: 32 additions & 0 deletions lib/models/transactions/messages/msg_withdraw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:meta/meta.dart';
import 'package:sacco/models/transactions/export.dart';

/// [MsgWithdrawDelegationReward] extends [StdMsg] and represents the message that should be
/// used when withdraw tokens.
class MsgWithdrawDelegationReward extends StdMsg {
/// Bech32 address of the sender.
final String delegator_address;

/// Bech32 address of the recipient.
final String validator_address;

/// Coins that will be sent.
final List<StdCoin> amount;

/// Public constructor.
MsgWithdrawDelegationReward({
@required this.delegator_address,
@required this.validator_address,
@required this.amount,
}) : assert(delegator_address != null),
assert(validator_address != null),
assert(amount != null),
super(type: "cosmos-sdk/MsgWithdrawDelegationReward", value: Map());

@override
Map<String, dynamic> get value => {
'delegator_address': this.delegator_address,
'validator_address': this.validator_address,
'amount': this.amount.map((coin) => coin.toJson()).toList(),
};
}
34 changes: 34 additions & 0 deletions test/models/msg_delegate_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';

import 'package:sacco/models/export.dart';

void main() {
test('MsgDelegate is built correctly', () {
final message = MsgDelegate(
delegator_address: "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
validator_address: "cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
amount: [StdCoin(denom: "umuon", amount: "1")],
);

expect(message.type, "cosmos-sdk/MsgDelegate");
expect(message.value, {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
});
expect(message.toJson(), {
"type": "cosmos-sdk/MsgDelegate",
"value": {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
}
});
});
}
42 changes: 42 additions & 0 deletions test/models/msg_redelegate_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:sacco/models/transactions/messages/msg_redelegate.dart';
import 'package:test/test.dart';

import 'package:sacco/models/export.dart';

void main() {
test('MsgBeginRedelegate is built correctly', () {
final message = MsgBeginRedelegate(
delegator_address: "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
validator_src_address:
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
validator_dst_address:
"cosmosvaloper185n9jln2g4w79w39m0g85x2tns6uekqg8hrx3j",
amount: [StdCoin(denom: "umuon", amount: "1")],
);

expect(message.type, "cosmos-sdk/MsgBeginRedelegate");
expect(message.value, {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_src_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"validator_dst_address":
"cosmosvaloper185n9jln2g4w79w39m0g85x2tns6uekqg8hrx3j",
"amount": [
{"amount": "1", "denom": "umuon"}
]
});
expect(message.toJson(), {
"type": "cosmos-sdk/MsgBeginRedelegate",
"value": {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_src_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"validator_dst_address":
"cosmosvaloper185n9jln2g4w79w39m0g85x2tns6uekqg8hrx3j",
"amount": [
{"amount": "1", "denom": "umuon"}
]
}
});
});
}
34 changes: 34 additions & 0 deletions test/models/msg_undelegate_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';

import 'package:sacco/models/export.dart';

void main() {
test('MsgUndelegate is built correctly', () {
final message = MsgUndelegate(
delegator_address: "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
validator_address: "cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
amount: [StdCoin(denom: "umuon", amount: "1")],
);

expect(message.type, "cosmos-sdk/MsgUndelegate");
expect(message.value, {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
});
expect(message.toJson(), {
"type": "cosmos-sdk/MsgUndelegate",
"value": {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
}
});
});
}
34 changes: 34 additions & 0 deletions test/models/msg_withdraw_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';

import 'package:sacco/models/export.dart';

void main() {
test('MsgWithdrawDelegationReward is built correctly', () {
final message = MsgWithdrawDelegationReward(
delegator_address: "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
validator_address: "cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
amount: [StdCoin(denom: "umuon", amount: "1")],
);

expect(message.type, "cosmos-sdk/MsgWithdrawDelegationReward");
expect(message.value, {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
});
expect(message.toJson(), {
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9",
"validator_address":
"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk",
"amount": [
{"amount": "1", "denom": "umuon"}
]
}
});
});
}
1 change: 1 addition & 0 deletions test_resources/DelegateTx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgDelegate","value":{"delegator_address":"cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":null,"memo":""}}
1 change: 1 addition & 0 deletions test_resources/DelegateTxSigned.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgDelegate","value":{"delegator_address":"cosmos1c0qp24pq92xz5c96usknlxcmwls3pze95u50m9","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AxsJA1LMoaxKOkWVwEJ37utjhYDhCLQrzo0EmST931rt"},"signature":"BXFstwJ+6pMRSz+vH/mY9F5yj+eJ11IGWefsvggrNmIY6uQFxIqQSBAn5WATeWxUXB0+NwP68UGo9xU+01xElw=="}],"memo":""}}
29 changes: 1 addition & 28 deletions test_resources/NodeInfoResponse.json
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
{
"node_info": {
"protocol_version": {
"p2p": "7",
"block": "10",
"app": "0"
},
"id": "1e219e6878d07ddb875fe2732811107e002e236b",
"listen_addr": "tcp://0.0.0.0:26656",
"network": "cosmos-hub2",
"version": "0.32.2",
"channels": "4020212223303800",
"moniker": "edge",
"other": {
"tx_index": "on",
"rpc_address": "tcp://0.0.0.0:26657"
}
},
"application_version": {
"name": "",
"server_name": "\u003cappd\u003e",
"client_name": "\u003cappcli\u003e",
"version": "1.1.0",
"commit": "",
"build_tags": "",
"go": "go version go1.12.9 linux/amd64"
}
}
{"node_info":{"protocol_version":{"p2p":"7","block":"10","app":"0"},"id":"1e219e6878d07ddb875fe2732811107e002e236b","listen_addr":"tcp://0.0.0.0:26656","network":"cosmos-hub2","version":"0.32.2","channels":"4020212223303800","moniker":"edge","other":{"tx_index":"on","rpc_address":"tcp://0.0.0.0:26657"}},"application_version":{"name":"","server_name":"\u003cappd\u003e","client_name":"\u003cappcli\u003e","version":"1.1.0","commit":"","build_tags":"","go":"goversiongo1.12.9linux/amd64"}}
1 change: 1 addition & 0 deletions test_resources/RedelegateTx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgBeginRedelegate","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_src_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","validator_dst_address":"cosmosvaloper185n9jln2g4w79w39m0g85x2tns6uekqg8hrx3j","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":null,"memo":""}}
1 change: 1 addition & 0 deletions test_resources/RedelegateTxSigned.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgBeginRedelegate","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_src_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","validator_dst_address":"cosmosvaloper185n9jln2g4w79w39m0g85x2tns6uekqg8hrx3j","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AzeAF3MK4XIXLHMe1SRB8apoLA9HzuR4M4gVw9s9cLQg"},"signature":"xCLKS+3xVUsIAI/E/HNy6x5fdKcypFxIycWh0qU75zcJkEQr+4FMiQXG8oMmnvVk/IgpIs5lOBaOPWbVasuMyA=="}],"memo":""}}
1 change: 1 addition & 0 deletions test_resources/UndelegateTx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgUndelegate","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":null,"memo":""}}
1 change: 1 addition & 0 deletions test_resources/UndelegateTxSigned.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgUndelegate","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk","amount":{"denom":"umuon","amount":"1"}}}],"fee":{"amount":[],"gas":"200000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AzeAF3MK4XIXLHMe1SRB8apoLA9HzuR4M4gVw9s9cLQg"},"signature":"aQDJawlh0noGQwx8fyDJbzeALQTvakMQrz8KaIAcbSpO/3tjuMZLTtbu3yi+diMETHdEWzM8prtlcepUxGhwgw=="}],"memo":""}}
1 change: 1 addition & 0 deletions test_resources/WithdrawDelegationRewardTx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgWithdrawDelegationReward","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk"}}],"fee":{"amount":[],"gas":"200000"},"signatures":null,"memo":""}}
1 change: 1 addition & 0 deletions test_resources/WithdrawDelegationRewardTxSigned.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgWithdrawDelegationReward","value":{"delegator_address":"cosmos1wappdlqgk2aeff3q2fsyllsug9gnzfjgh2na7p","validator_address":"cosmosvaloper1c0qp24pq92xz5c96usknlxcmwls3pze93gq6hk"}}],"fee":{"amount":[],"gas":"200000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AzeAF3MK4XIXLHMe1SRB8apoLA9HzuR4M4gVw9s9cLQg"},"signature":"D3RN3zxwkpXiibYRiL4JyN0wvxSDLSd3Hg17ZbWyWaEeNzdFshDd318yjowzcP7g/8sPJitrzCqxMfa7G5rUyg=="}],"memo":""}}