Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
Enhanced Cardano Network Support
  • Loading branch information
mrtnetwork committed Mar 16, 2024
1 parent 7db8471 commit 762e656
Show file tree
Hide file tree
Showing 32 changed files with 125 additions and 144 deletions.
4 changes: 2 additions & 2 deletions example/lib/example/cardano/deploy_plutus_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void main() async {
final externalAddress = ADABaseAddress.fromPublicKey(
basePubkeyBytes: external.bip44.publicKey.compressed,
stakePubkeyBytes: external.bip44Sk.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
final internalAddress = ADABaseAddress.fromPublicKey(
basePubkeyBytes: internal.bip44.publicKey.compressed,
stakePubkeyBytes: internal.bip44Sk.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

PlutusList plutusData = PlutusData.fromJsonSchema(
json: StringUtils.toJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ void main() async {
final receiver = ADABaseAddress.fromPublicKey(
basePubkeyBytes: byronLegacy.masterPublicKey.compressed,
stakePubkeyBytes: byronLegacy.masterPublicKey.compressed,
network: AdaNetwork.testnet);
network: ADANetwork.testnet);
final receiver2 = ADAByronAddress.fromPublicKey(
chaincode: pubkey.chainCode.toBytes(),
publicKey: pubkey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
final addr = ADAByronAddress.legacy(
network: AdaNetwork.testnetPreprod,
network: ADANetwork.testnetPreprod,
chaincode: BytesUtils.fromHexString(
"0a45cc2bb6a5327ec85fe580145ca465bd4876212e84cf74f7d61e67e2736dc1"),
hdPath: "m/0'/2'",
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example/cardano/legacy_to_legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ void main() async {
final adaPrivateKey = AdaPrivateKey.fromBytes(privateKey.raw);
final receiverLegacy = ADAByronAddress(
"KjgoiXJS2coQ3nS6mdqjBvy1HnFKgiZEeTbNTtncA1HgTEDnbkhXkFKBQn5DxXiGZ4nZp25VtcqvMfpg4QRPdVELJE8LpWkyLav3kcKyXc2w",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
final multiSig = ADAByronAddress(
"KjgoiXJS2coqEj7BmUEY9TSJxppxySTBNDskVreRH2VN9TGV2SX1b8BRstVaPAA7eWCsEFLg8VKj47mNLJ5M21qPiaZqxphEYDBjdwvg44ot",
network: AdaNetwork.testnetPreprod,
network: ADANetwork.testnetPreprod,
);
final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ void main() async {
final receiver = ADABaseAddress.fromPublicKey(
basePubkeyBytes: byronLegacyWallet.masterPublicKey.compressed,
stakePubkeyBytes: byronLegacyWallet.masterPublicKey.compressed,
network: AdaNetwork.testnet);
network: ADANetwork.testnet);
final receiver2 = ADAByronAddress.fromPublicKey(
chaincode: pubkey.chainCode.toBytes(),
publicKey: pubkey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final multiSig = ADAByronAddress(
"KjgoiXJS2coqEj7BmUEY9TSJxppxySTBNDskVreRH2VN9TGV2SX1b8BRstVaPAA7eWCsEFLg8VKj47mNLJ5M21qPiaZqxphEYDBjdwvg44ot",
network: AdaNetwork.testnetPreprod,
network: ADANetwork.testnetPreprod,
);

final provider = BlockforestProvider(BlockforestHTTPProvider(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/mint_nft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() async {
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);
ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ void main() async {

ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
ADAEnterpriseAddress receiver = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend2.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/mint_with_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() async {

ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/pool_registration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() async {
final receiver = ADABaseAddress.fromPublicKey(
basePubkeyBytes: spend.publicKey.compressed,
stakePubkeyBytes: spend2.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final reward = receiver.stakeAddress();
final metadata = TransactionMetadata.fromJsonSchema(json: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {
final stakePrivateKey =
AdaPrivateKey.fromBytes(internal10.bip44Sk.privateKey.raw);
final addr = ADABaseAddress.shellyWallet(
shelleyWallet: internal10, network: AdaNetwork.testnetPreprod);
shelleyWallet: internal10, network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/register_stake_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() async {
final receiver = ADABaseAddress.fromPublicKey(
basePubkeyBytes: spend.publicKey.compressed,
stakePubkeyBytes: spend2.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example/cardano/shelly_1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ void main() async {

ADAEnterpriseAddress addr = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
8 changes: 4 additions & 4 deletions example/lib/example/cardano/shelly_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ void main() async {
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);
ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vzkrh0ytcw257np6x6lxp74a6p4erj7rqt9azycnckgp2fgw82qet",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
ADABaseAddress receiver2 = ADABaseAddress(
"addr_test1qzkrh0ytcw257np6x6lxp74a6p4erj7rqt9azycnckgp2f27p5uc85frnln985tjn0xv8fmdv4t696d3j9zvu0ktx0gs62w8wv",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

ADAPointerAddress receiver3 = ADAPointerAddress(
"addr_test1gzkrh0ytcw257np6x6lxp74a6p4erj7rqt9azycnckgp2fgpqyqskrjv3p",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example/cardano/shelly_3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ void main() async {
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);
ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: privateKey.publicKey().toBytes(),
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vpmlrrdzzl68qdr3y7jjzyfmyepnnyjs3lxquckzxc8ysggzzfs29",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/shelly_32byte_private_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() async {

ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
2 changes: 1 addition & 1 deletion example/lib/example/cardano/shelly_to_legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() async {

ADAByronAddress receiver = ADAByronAddress(
"FHnt4NL7yPXpa2nSSgu36kbQw4jpxWR3V5Yr7MEaPjWa58V3doFnkj3rwzhTTEX",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example/cardano/shelly_with_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ void main() async {

ADAEnterpriseAddress addr = ADAEnterpriseAddress.fromPublicKey(
pubkeyBytes: spend.publicKey.compressed,
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example/cardano/spend_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ void main() async {
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);
ADAEnterpriseAddress addr = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);
ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ void main() async {

ADAEnterpriseAddress addr = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: AdaNetwork.testnetPreprod);
network: ADANetwork.testnetPreprod);

final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
Expand Down
24 changes: 12 additions & 12 deletions lib/ada/src/address/era/byron/byron.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class ADAByronAddress extends ADAAddress {
String get bech32Address => extendedAddress.toBech32();

/// Extended address containing additional information.
final AdaByronAddr extendedAddress;
final ADAByronAddr extendedAddress;

/// The ADA network associated with this address.
@override
final AdaNetwork network;
final ADANetwork network;

/// Constructor for ADAByronAddress.
const ADAByronAddress._(this.address, this.extendedAddress, this.network)
: super.init();

/// Factory constructor to create an ADAByronAddress instance from a given address string.
factory ADAByronAddress(String address, {AdaNetwork? network}) {
factory ADAByronAddress(String address, {ADANetwork? network}) {
final decode = AdaAddressUtils.decodeAddres(address,
addrType: AdaAddressType.byron, network: network);
addrType: ADAAddressType.byron, network: network);
return ADAByronAddress._(decode.byronAddrPayload!.encode(),
decode.byronAddrPayload!, decode.network);
}
Expand All @@ -39,7 +39,7 @@ class ADAByronAddress extends ADAAddress {
required List<int> chaincode,
List<int>? hdPathKey,
String? hdPath,
AdaNetwork network = AdaNetwork.mainnet}) {
ADANetwork network = ADANetwork.mainnet}) {
if (hdPath != null && hdPathKey != null) {
return ADAByronAddress.legacy(
publicKey: publicKey,
Expand All @@ -56,7 +56,7 @@ class ADAByronAddress extends ADAAddress {
/// Factory constructor to create an ADAByronAddress instance from a Bip32 structure.
factory ADAByronAddress.fromBip32(
{required CardanoByronLegacyBip32 bip32,
AdaNetwork network = AdaNetwork.mainnet}) {
ADANetwork network = ADANetwork.mainnet}) {
final encode = AdaByronIcarusAddrEncoder().encodeKeyWithInfo(
bip32.publicKey.compressed, {
"net_tag": network,
Expand All @@ -68,7 +68,7 @@ class ADAByronAddress extends ADAAddress {
/// Factory constructor to create an ADAByronAddress instance from an Icarus structure.
factory ADAByronAddress.fromIcarus(
{required CardanoIcarusBip32 bip32,
AdaNetwork network = AdaNetwork.mainnet}) {
ADANetwork network = ADANetwork.mainnet}) {
final encode = AdaByronIcarusAddrEncoder().encodeKeyWithInfo(
bip32.publicKey.compressed, {
"net_tag": network,
Expand All @@ -82,7 +82,7 @@ class ADAByronAddress extends ADAAddress {
{required CardanoByronLegacy bip32,
required Bip32KeyIndex firstIndex,
required Bip32KeyIndex secondIndex,
AdaNetwork network = AdaNetwork.mainnet}) {
ADANetwork network = ADANetwork.mainnet}) {
final publicKey =
bip32.getPublicKey(firstIndex: firstIndex, secondIndex: secondIndex);
final encode = AdaByronLegacyAddrEncoder()
Expand All @@ -101,7 +101,7 @@ class ADAByronAddress extends ADAAddress {
required List<int> chaincode,
required List<int> hdPathKey,
required String hdPath,
AdaNetwork network = AdaNetwork.mainnet}) {
ADANetwork network = ADANetwork.mainnet}) {
final encode = AdaByronLegacyAddrEncoder().encodeKeyWithInfo(publicKey, {
"net_tag": network,
"chain_code": chaincode,
Expand All @@ -118,9 +118,9 @@ class ADAByronAddress extends ADAAddress {

/// Deserializes a CBOR object into an ADAByronAddress instance.
static ADAByronAddress deserialize(CborBytesValue cbor,
{AdaNetwork? network}) {
{ADANetwork? network}) {
final CborListValue cborList = CborObject.fromCbor(cbor.value).cast();
final addr = AdaByronAddr.deserialize(cborList.encode());
final addr = ADAByronAddr.deserialize(cborList.encode());
return ADAByronAddress(addr.encode(), network: network);
}

Expand All @@ -138,5 +138,5 @@ class ADAByronAddress extends ADAAddress {

/// Returns the address type, which is ADAAddressType.byron.
@override
AdaAddressType get addressType => AdaAddressType.byron;
ADAAddressType get addressType => ADAAddressType.byron;
}
14 changes: 7 additions & 7 deletions lib/ada/src/address/era/core/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import 'package:on_chain/ada/src/serialization/cbor_serialization.dart';
/// Represents an abstract class for ADA addresses with serialization capabilities.
abstract class ADAAddress with ADASerialization {
/// Abstract property representing the ADA network.
abstract final AdaNetwork network;
abstract final ADANetwork network;

/// Abstract property representing the address string.
abstract final String address;

/// Abstract property representing the type of ADA address.
abstract final AdaAddressType addressType;
abstract final ADAAddressType addressType;

/// Abstract property representing the Bech32 address.
abstract final String bech32Address;
Expand All @@ -23,20 +23,20 @@ abstract class ADAAddress with ADASerialization {

/// Factory method to create an ADAAddress instance from a given address string.
static T fromAddress<T extends ADAAddress>(String address,
{AdaNetwork? network}) {
{ADANetwork? network}) {
final type = AdaAddressUtils.findAddrType(address);
final ADAAddress addr;
switch (type) {
case AdaAddressType.base:
case ADAAddressType.base:
addr = ADABaseAddress(address, network: network);
break;
case AdaAddressType.pointer:
case ADAAddressType.pointer:
addr = ADAPointerAddress(address, network: network);
break;
case AdaAddressType.reward:
case ADAAddressType.reward:
addr = ADARewardAddress(address, network: network);
break;
case AdaAddressType.enterprise:
case ADAAddressType.enterprise:
addr = ADAEnterpriseAddress(address, network: network);
break;
default:
Expand Down
Loading

0 comments on commit 762e656

Please sign in to comment.