Skip to content

Commit

Permalink
rename shelley to jormungandr
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Jul 7, 2020
1 parent 1447cb5 commit 2f394c5
Show file tree
Hide file tree
Showing 50 changed files with 179 additions and 180 deletions.
44 changes: 23 additions & 21 deletions app/api/ada/index.js
Expand Up @@ -30,7 +30,7 @@ import {
} from './lib/storage/bridge/walletBuilder/byron';
import {
createStandardCip1852Wallet,
} from './lib/storage/bridge/walletBuilder/shelley';
} from './lib/storage/bridge/walletBuilder/jormungandr';
import {
getAllTransactions,
updateTransactions,
Expand Down Expand Up @@ -86,14 +86,14 @@ import {
signTransaction as byronSignTransaction,
} from './transactions/byron/transactionsV2';
import {
sendAllUnsignedTx as shelleySendAllUnsignedTx,
newAdaUnsignedTx as shelleyNewAdaUnsignedTx,
asAddressedUtxo as shelleyAsAddressedUtxo,
signTransaction as shelleySignTransaction,
} from './transactions/shelley/utxoTransactions';
sendAllUnsignedTx as jormungandrSendAllUnsignedTx,
newAdaUnsignedTx as jormungandrNewAdaUnsignedTx,
asAddressedUtxo as jormungandrAsAddressedUtxo,
signTransaction as jormungandrSignTransaction,
} from './transactions/jormungandr/utxoTransactions';
import {
normalizeKey
} from './transactions/shelley/utils';
} from './transactions/jormungandr/utils';
import {
generateWalletRootKey,
generateAdaMnemonic,
Expand Down Expand Up @@ -126,7 +126,7 @@ import {
import LocalizableError from '../../i18n/LocalizableError';
import { scanBip44Account, } from '../common/lib/restoration/bip44';
import { v2genAddressBatchFunc, } from './restoration/byron/scan';
import { scanCip1852Account, } from './restoration/shelley/scan';
import { scanCip1852Account, } from './restoration/jormungandr/scan';
import type {
BaseSignRequest,
UnsignedTxResponse,
Expand Down Expand Up @@ -685,7 +685,7 @@ export default class AdaApi {
id = signedTx.id();
encodedTx = Buffer.from(signedTx.to_hex(), 'hex');
} else if (unsignedTx instanceof RustModule.WalletV3.InputOutput) {
const signedTx = shelleySignTransaction(
const signedTx = jormungandrSignTransaction(
{
senderUtxos: signRequest.senderUtxos,
changeAddr: signRequest.changeAddr,
Expand Down Expand Up @@ -849,13 +849,13 @@ export default class AdaApi {
const isJormungandr = network.NetworkId === networks.JormungandrMainnet.NetworkId;

const addressedUtxo = isJormungandr
? shelleyAsAddressedUtxo(filteredUtxos)
? jormungandrAsAddressedUtxo(filteredUtxos)
: byronAsAddressedUtxo(filteredUtxos);

let unsignedTxResponse;
if (request.shouldSendAll != null) {
unsignedTxResponse = isJormungandr
? shelleySendAllUnsignedTx(
? jormungandrSendAllUnsignedTx(
receiver,
addressedUtxo
)
Expand All @@ -871,7 +871,7 @@ export default class AdaApi {
}
const changeAddr = nextUnusedInternal.addressInfo;
unsignedTxResponse = isJormungandr
? shelleyNewAdaUnsignedTx(
? jormungandrNewAdaUnsignedTx(
[{
address: receiver,
amount
Expand Down Expand Up @@ -919,13 +919,13 @@ export default class AdaApi {
const certificate = RustModule.WalletV3.Certificate.stake_delegation(stakeDelegationCert);

const allUtxo = await request.publicDeriver.getAllUtxos();
const addressedUtxo = shelleyAsAddressedUtxo(allUtxo);
const addressedUtxo = jormungandrAsAddressedUtxo(allUtxo);
const nextUnusedInternal = await request.publicDeriver.nextInternal();
if (nextUnusedInternal.addressInfo == null) {
throw new Error(`${nameof(this.createDelegationTx)} no internal addresses left. Should never happen`);
}
const changeAddr = nextUnusedInternal.addressInfo;
const unsignedTx = shelleyNewAdaUnsignedTx(
const unsignedTx = jormungandrNewAdaUnsignedTx(
[],
[{
address: changeAddr.addr.Hash,
Expand Down Expand Up @@ -988,7 +988,7 @@ export default class AdaApi {
throw new Error(`${nameof(this.signAndBroadcastDelegationTx)} missing certificate`);
}
const certificate = request.signRequest.certificate;
const signedTx = shelleySignTransaction(
const signedTx = jormungandrSignTransaction(
{
senderUtxos: signRequest.senderUtxos,
changeAddr: signRequest.changeAddr,
Expand Down Expand Up @@ -1185,10 +1185,12 @@ export default class AdaApi {
const reverseAddressLookup = new Map<number, Array<string>>();
const foundAddresses = new Set<string>();

const sourceIsShelleyWallet = request.transferSource === TransferSource.SHELLEY_UTXO ||
request.transferSource === TransferSource.SHELLEY_CHIMERIC_ACCOUNT;
const sourceIsJormungandrWallet = (
request.transferSource === TransferSource.JORMUNGANDR_UTXO ||
request.transferSource === TransferSource.JORMUNGANDR_CHIMERIC_ACCOUNT
);
const accountKey = rootPk
.derive(sourceIsShelleyWallet
.derive(sourceIsJormungandrWallet
? WalletTypePurpose.CIP1852
: WalletTypePurpose.BIP44)
.derive(CoinTypes.CARDANO)
Expand Down Expand Up @@ -1226,7 +1228,7 @@ export default class AdaApi {
addByHash,
type: CoreAddressTypes.CARDANO_LEGACY,
});
} else if (sourceIsShelleyWallet) {
} else if (sourceIsJormungandrWallet) {
const stakingKey = accountKey
.derive(ChainDerivations.CHIMERIC_ACCOUNT)
.derive(STAKING_KEY_INDEX)
Expand All @@ -1242,11 +1244,11 @@ export default class AdaApi {
stakingKey,
});

if (request.transferSource === TransferSource.SHELLEY_UTXO) {
if (request.transferSource === TransferSource.JORMUNGANDR_UTXO) {
insertTree = cip1852InsertTree.filter(child => (
child.index === ChainDerivations.EXTERNAL || child.index === ChainDerivations.INTERNAL
));
} else if (request.transferSource === TransferSource.SHELLEY_CHIMERIC_ACCOUNT) {
} else if (request.transferSource === TransferSource.JORMUNGANDR_CHIMERIC_ACCOUNT) {
insertTree = cip1852InsertTree.filter(child => (
child.index === ChainDerivations.CHIMERIC_ACCOUNT
));
Expand Down
2 changes: 1 addition & 1 deletion app/api/ada/lib/storage/bridge/tests/common.js
Expand Up @@ -15,7 +15,7 @@ import {
} from '../walletBuilder/byron';
import {
createStandardCip1852Wallet
} from '../walletBuilder/shelley';
} from '../walletBuilder/jormungandr';
import {
HARD_DERIVATION_START,
WalletTypePurpose,
Expand Down
12 changes: 6 additions & 6 deletions app/api/ada/lib/storage/bridge/tests/mockNetwork.js
Expand Up @@ -67,7 +67,7 @@ function ourAddressesInTx(
const addressesUsed = new Set();
for (const addr of addresses) {
const kind = addressToKind(addr, 'bytes');
const payload = kind === CoreAddressTypes.SHELLEY_GROUP
const payload = kind === CoreAddressTypes.JORMUNGANDR_GROUP
? groupToSingle(addr)
: addr;
if (ownAddresses.has(payload)) {
Expand Down Expand Up @@ -220,8 +220,8 @@ export function genUtxoForAddresses(
const kind = addressToKind(address, 'bytes');
if (
kind !== CoreAddressTypes.CARDANO_LEGACY &&
kind !== CoreAddressTypes.SHELLEY_SINGLE &&
kind !== CoreAddressTypes.SHELLEY_GROUP
kind !== CoreAddressTypes.JORMUNGANDR_SINGLE &&
kind !== CoreAddressTypes.JORMUNGANDR_GROUP
) {
throw new Error('genUtxoForAddresses non-utxo address in utxo endpoint');
}
Expand Down Expand Up @@ -329,21 +329,21 @@ export function getAddressForType(
const derivedKey = derivePath(rootKey, path);

switch (type) {
case CoreAddressTypes.SHELLEY_SINGLE: {
case CoreAddressTypes.JORMUNGANDR_SINGLE: {
const addr = RustModule.WalletV3.Address.single_from_public_key(
derivedKey.to_public().to_raw_key(),
RustModule.WalletV3.AddressDiscrimination.Production,
);
return Buffer.from(addr.as_bytes()).toString('hex');
}
case CoreAddressTypes.SHELLEY_ACCOUNT: {
case CoreAddressTypes.JORMUNGANDR_ACCOUNT: {
const addr = RustModule.WalletV3.Address.account_from_public_key(
derivedKey.to_public().to_raw_key(),
RustModule.WalletV3.AddressDiscrimination.Production,
);
return Buffer.from(addr.as_bytes()).toString('hex');
}
case CoreAddressTypes.SHELLEY_GROUP: {
case CoreAddressTypes.JORMUNGANDR_GROUP: {
const newPath = [...path];
// -1 because newPath here starts at PURPOSE and not at ROOT
const chainLevel = 4 - 1;
Expand Down
24 changes: 12 additions & 12 deletions app/api/ada/lib/storage/bridge/tests/shelleyGroup.test.js
Expand Up @@ -89,7 +89,7 @@ const firstTx: void => Array<RemoteTransaction> = () => [{
ChainDerivations.EXTERNAL,
4
],
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
amount: '2100000'
},
Expand Down Expand Up @@ -132,7 +132,7 @@ const nextRegularSpend: void => Array<RemoteTransaction> = () => [{
ChainDerivations.EXTERNAL,
4
],
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
amount: '2100000',
id: '29f2fe214ec2c9b05773a689eca797e903adeaaf51dfe20782a4bf401e7ed5450',
Expand All @@ -153,7 +153,7 @@ const nextRegularSpend: void => Array<RemoteTransaction> = () => [{
ChainDerivations.INTERNAL,
0
],
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
amount: '1100000'
},
Expand All @@ -167,7 +167,7 @@ const nextRegularSpend: void => Array<RemoteTransaction> = () => [{
ChainDerivations.EXTERNAL,
19
],
CoreAddressTypes.SHELLEY_SINGLE
CoreAddressTypes.JORMUNGANDR_SINGLE
),
amount: '900000'
}
Expand Down Expand Up @@ -273,7 +273,7 @@ const txWithCert: void => Array<RemoteTransaction> = () => [{
ChainDerivations.EXTERNAL,
4
],
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
amount: '2100000'
},
Expand All @@ -287,7 +287,7 @@ const txWithCert: void => Array<RemoteTransaction> = () => [{
ChainDerivations.INTERNAL,
12
],
CoreAddressTypes.SHELLEY_SINGLE
CoreAddressTypes.JORMUNGANDR_SINGLE
),
amount: '1731391'
}
Expand Down Expand Up @@ -320,7 +320,7 @@ const secondCertTx: ('Pending' | 'Successful') => RemoteTransaction = status =>
ChainDerivations.INTERNAL,
12
],
CoreAddressTypes.SHELLEY_SINGLE
CoreAddressTypes.JORMUNGANDR_SINGLE
),
amount: '1731391',
id: '29f2fe214ec2c9b05773a689eca797e903adeaaf51dfe20782a4bf401e7ed5451',
Expand All @@ -341,7 +341,7 @@ const secondCertTx: ('Pending' | 'Successful') => RemoteTransaction = status =>
ChainDerivations.EXTERNAL,
4
],
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
amount: '1000000'
},
Expand All @@ -355,7 +355,7 @@ const secondCertTx: ('Pending' | 'Successful') => RemoteTransaction = status =>
ChainDerivations.INTERNAL,
13
],
CoreAddressTypes.SHELLEY_SINGLE
CoreAddressTypes.JORMUNGANDR_SINGLE
),
amount: '200000'
}
Expand Down Expand Up @@ -415,7 +415,7 @@ async function syncingSimpleTransaction(): Promise<void> {
address: getAddressForType(
TX_TEST_MNEMONIC_1,
expectedAddressing,
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
addressing: {
path: expectedAddressing,
Expand Down Expand Up @@ -505,7 +505,7 @@ async function syncingSimpleTransaction(): Promise<void> {
address: getAddressForType(
TX_TEST_MNEMONIC_1,
expectedAddressing1,
CoreAddressTypes.SHELLEY_GROUP
CoreAddressTypes.JORMUNGANDR_GROUP
),
addressing: {
path: expectedAddressing1,
Expand Down Expand Up @@ -537,7 +537,7 @@ async function syncingSimpleTransaction(): Promise<void> {
address: getAddressForType(
TX_TEST_MNEMONIC_1,
expectedAddressing2,
CoreAddressTypes.SHELLEY_SINGLE
CoreAddressTypes.JORMUNGANDR_SINGLE
),
addressing: {
path: expectedAddressing2,
Expand Down
8 changes: 4 additions & 4 deletions app/api/ada/lib/storage/bridge/updateTransactions.js
Expand Up @@ -975,7 +975,7 @@ async function rawUpdateTransactions(
...utxoAddresses
// Note: don't send group keys
// Okay to filter them because the payment key is duplicated inside the single addresses
.filter(address => address.Type !== CoreAddressTypes.SHELLEY_GROUP)
.filter(address => address.Type !== CoreAddressTypes.JORMUNGANDR_GROUP)
.map(address => address.Hash),
...accountingAddresses.map(address => address.Hash),
],
Expand Down Expand Up @@ -1314,8 +1314,8 @@ async function networkTxToDbTx(
// since the payment (UTXO) key is the one that signs
if (
txType === CoreAddressTypes.CARDANO_LEGACY ||
txType === CoreAddressTypes.SHELLEY_SINGLE ||
txType === CoreAddressTypes.SHELLEY_GROUP
txType === CoreAddressTypes.JORMUNGANDR_SINGLE ||
txType === CoreAddressTypes.JORMUNGANDR_GROUP
) {
utxoOutputs.push({
TransactionId: txRowId,
Expand All @@ -1330,7 +1330,7 @@ async function networkTxToDbTx(
IsUnspent: true,
});
} else if (
txType === CoreAddressTypes.SHELLEY_ACCOUNT
txType === CoreAddressTypes.JORMUNGANDR_ACCOUNT
) {
accountingOutputs.push({
TransactionId: txRowId,
Expand Down
18 changes: 14 additions & 4 deletions app/api/ada/lib/storage/bridge/utils.js
Expand Up @@ -35,17 +35,27 @@ export function addressToKind(
: RustModule.WalletV3.Address.from_string(address);

switch (wasmAddr.get_kind()) {
case RustModule.WalletV3.AddressKind.Single: return CoreAddressTypes.SHELLEY_SINGLE;
case RustModule.WalletV3.AddressKind.Group: return CoreAddressTypes.SHELLEY_GROUP;
case RustModule.WalletV3.AddressKind.Account: return CoreAddressTypes.SHELLEY_ACCOUNT;
case RustModule.WalletV3.AddressKind.Multisig: return CoreAddressTypes.SHELLEY_MULTISIG;
case RustModule.WalletV3.AddressKind.Single: return CoreAddressTypes.JORMUNGANDR_SINGLE;
case RustModule.WalletV3.AddressKind.Group: return CoreAddressTypes.JORMUNGANDR_GROUP;
case RustModule.WalletV3.AddressKind.Account: return CoreAddressTypes.JORMUNGANDR_ACCOUNT;
case RustModule.WalletV3.AddressKind.Multisig: return CoreAddressTypes.JORMUNGANDR_MULTISIG;
default: throw new Error(`${nameof(addressToKind)} unknown address type ` + address);
}
} catch (e1) {
throw new Error(`${nameof(addressToKind)} failed to parse address type ${e1} ${address}`);
}
}

export function isJormungandrAddress(
kind: CoreAddressT
): boolean {
if (kind === CoreAddressTypes.JORMUNGANDR_SINGLE) return true;
if (kind === CoreAddressTypes.JORMUNGANDR_GROUP) return true;
if (kind === CoreAddressTypes.JORMUNGANDR_ACCOUNT) return true;
if (kind === CoreAddressTypes.JORMUNGANDR_MULTISIG) return true;
return false;
}

export function groupToSingle(
groupAddress: string
): string {
Expand Down
Expand Up @@ -37,9 +37,9 @@ import type {
import type { AddByHashFunc } from '../../../../../common/lib/storage/bridge/hashMapper';
import { rawGenAddByHash } from '../../../../../common/lib/storage/bridge/hashMapper';
import {
addShelleyUtxoAddress,
addShelleyChimericAccountAddress,
} from '../../../../restoration/shelley/scan';
addJormungandrUtxoAddress,
addJormungandrChimericAccountAddress,
} from '../../../../restoration/jormungandr/scan';
import { KeyKind } from '../../../../../common/lib/crypto/keys/types';
import { networks } from '../../database/prepackaged/networks';

Expand Down Expand Up @@ -99,7 +99,7 @@ export async function getAccountDefaultDerivations(
const externalAddresses = addressesIndex.map(i => ({
index: i,
insert: async insertRequest => {
return await addShelleyUtxoAddress(
return await addJormungandrUtxoAddress(
addByHash,
insertRequest,
stakingKey,
Expand All @@ -110,7 +110,7 @@ export async function getAccountDefaultDerivations(
const internalAddresses = addressesIndex.map(i => ({
index: i,
insert: async insertRequest => {
return await addShelleyUtxoAddress(
return await addJormungandrUtxoAddress(
addByHash,
insertRequest,
stakingKey,
Expand All @@ -121,7 +121,7 @@ export async function getAccountDefaultDerivations(
const accountAddress = [0].map(i => ({
index: i,
insert: async insertRequest => {
return await addShelleyChimericAccountAddress(
return await addJormungandrChimericAccountAddress(
addByHash,
insertRequest,
stakingKey,
Expand Down

0 comments on commit 2f394c5

Please sign in to comment.