Skip to content

Commit

Permalink
Merge pull request cardano-foundation#193 from input-output-hk/chore/…
Browse files Browse the repository at this point in the history
…improve-utxo-operation-types

chore: replace transfer operation with input and output
  • Loading branch information
rhyslbw committed Oct 15, 2020
2 parents 58f7616 + d17f168 commit 74bc5be
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 214 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/nightly.yml
Expand Up @@ -42,23 +42,15 @@ jobs:
run: go install
- name: Prepare rosetta-cli configuration
working-directory: cardano-rosetta/test/check/configuration/src
run: |
mkdir ../out
jq -s '.[0] * .[1] * .[2] * .[3]' base.json network/mainnet.json data/host/localhost.json data/byron_sample.json > ../out/data_byron.json
rosetta-cli configuration:validate ../out/data_byron.json
jq -s '.[0] * .[1] * .[2] * .[3]' base.json network/mainnet.json data/host/localhost.json data/shelley_transition_sample.json > ../out/data_shelley_transition.json
rosetta-cli configuration:validate ../out/data_shelley_transition.json
jq -s '.[0] * .[1] * .[2] * .[3]' base.json network/mainnet.json data/host/localhost.json data/shelley_sample.json > ../out/data_shelley.json
rosetta-cli configuration:validate ../out/data_shelley.json
- name: check:data byron
working-directory: cardano-rosetta/test/check/configuration/out
run: rosetta-cli check:data --configuration-file=data_byron.json
working-directory: cardano-rosetta/test/check/configuration/data
run: rosetta-cli check:data --configuration-file byron_sample.json
- name: check:data shelley transition
working-directory: cardano-rosetta/test/check/configuration/out
run: rosetta-cli check:data --configuration-file=data_shelley_transition.json
working-directory: cardano-rosetta/test/check/configuration/data
run: rosetta-cli check:data --configuration-file shelley_transition.json
- name: check:data shelley
working-directory: cardano-rosetta/test/check/configuration/out
run: rosetta-cli check:data --configuration-file=data_shelley.json
working-directory: cardano-rosetta/test/check/configuration/data
run: rosetta-cli check:data --configuration-file shelley_sample.json
- name: Make data snapshot
env:
AWS_S3_BUCKET: cardano-data-cache
Expand Down
Expand Up @@ -71,7 +71,7 @@ const configure = (networkService: NetworkService, networkId: string, cardanoNod
},
allow: {
operation_statuses: [SUCCESS_OPERATION_STATE],
operation_types: [operationType.TRANSFER],
operation_types: [operationType.INPUT, operationType.OUTPUT],
errors: Object.values(ErrorFactory)
.map(fn => fn())
// Return them sorted by code
Expand Down
Expand Up @@ -4,7 +4,7 @@ import cbor from 'cbor';
import { Logger } from 'fastify';
import { ErrorFactory } from '../utils/errors';
import { hexFormatter } from '../utils/formatters';
import { ADA, ADA_DECIMALS, TRANSFER_OPERATION_TYPE } from '../utils/constants';
import { ADA, ADA_DECIMALS, operationType } from '../utils/constants';

// Nibbles
export const SIGNATURE_LENGTH = 128;
Expand Down Expand Up @@ -159,11 +159,11 @@ const parseInputToOperation = (input: CardanoWasm.TransactionInput, index: numbe
coin_identifier: {
identifier: `${hexFormatter(Buffer.from(input.transaction_id().to_bytes()))}:${input.index()}`
},
// FIXME: we have this as a constant in `block-service`. We should move to a converstion module.
// FIXME: we have this as a constant in `block-service`. We should move to a conversation module.
coin_action: 'coin_spent'
},
status: '',
type: TRANSFER_OPERATION_TYPE
type: operationType.INPUT
});

const parseOutputToOperation = (
Expand All @@ -177,7 +177,7 @@ const parseOutputToOperation = (
account: { address: output.address().to_bech32(addressPrefix) },
amount: { value: output.amount().to_str(), currency: { symbol: ADA, decimals: ADA_DECIMALS } },
status: '',
type: TRANSFER_OPERATION_TYPE
type: operationType.OUTPUT
});

const getRelatedOperationsFromInputs = (
Expand Down
4 changes: 2 additions & 2 deletions cardano-rosetta-server/src/server/utils/constants.ts
Expand Up @@ -12,14 +12,14 @@ export const VOUT = 'Vout';
export const SIGNATURE_TYPE = 'ed25519';

export enum operationType {
TRANSFER = 'transfer'
INPUT = 'input',
OUTPUT = 'output'
}

enum operationTypeStatus {
SUCCESS = 'success'
}

export const TRANSFER_OPERATION_TYPE = 'transfer';
export const SUCCESS_STATUS = 'success';

export const MAINNET = 'mainnet';
Expand Down
16 changes: 4 additions & 12 deletions cardano-rosetta-server/src/server/utils/data-mapper.ts
@@ -1,17 +1,9 @@
/* eslint-disable camelcase */

import cbor from 'cbor';
import { NetworkIdentifier, UnsignedTransaction } from '../services/cardano-services';
import { NetworkIdentifier } from '../services/cardano-services';
import { NetworkStatus } from '../services/network-service';
import {
ADA,
ADA_DECIMALS,
CARDANO,
MAINNET,
SIGNATURE_TYPE,
SUCCESS_STATUS,
TRANSFER_OPERATION_TYPE
} from './constants';
import { ADA, ADA_DECIMALS, CARDANO, MAINNET, operationType, SIGNATURE_TYPE, SUCCESS_STATUS } from './constants';
import { Block, BlockUtxos, Network, TransactionWithInputsAndOutputs, Utxo } from '../models';

const COIN_SPENT_ACTION = 'coin_spent';
Expand Down Expand Up @@ -82,7 +74,7 @@ export const mapToRosettaTransaction = (
const inputsAsOperations = transaction.inputs.map((input, index) =>
createOperation(
index,
TRANSFER_OPERATION_TYPE,
operationType.INPUT,
SUCCESS_STATUS,
input.address,
`-${input.value}`,
Expand All @@ -100,7 +92,7 @@ export const mapToRosettaTransaction = (
const outputsAsOperations = transaction.outputs.map((output, index) =>
createOperation(
inputsAsOperations.length + index,
TRANSFER_OPERATION_TYPE,
operationType.OUTPUT,
SUCCESS_STATUS,
output.address,
output.value,
Expand Down
50 changes: 25 additions & 25 deletions cardano-rosetta-server/test/e2e/fixture-data.ts
@@ -1,6 +1,6 @@
/* eslint-disable max-len */
import cbor from 'cbor';
import { SIGNATURE_TYPE } from '../../src/server/utils/constants';
import { operationType, SIGNATURE_TYPE } from '../../src/server/utils/constants';

/* eslint-disable camelcase */
const slotLeader2b1 = 'SlotLeader-52df0f2c5539b2b1';
Expand Down Expand Up @@ -76,7 +76,7 @@ export const block23236WithTransactions = {
operation_identifier: {
index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'Ae2tdPwUPEZH1TtKqx7VsvXUPAv2KaG7TkXJTfyb2bqFCctePknLVgVQyfn'
Expand Down Expand Up @@ -105,7 +105,7 @@ export const block23236WithTransactions = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address:
Expand Down Expand Up @@ -136,7 +136,7 @@ export const block23236WithTransactions = {
operation_identifier: {
index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'Ae2tdPwUPEZE74MFSWpMuXKTbh8uyc7GVXT8Rc4dk1kCUfVpX19jk1VW2CW'
Expand Down Expand Up @@ -165,7 +165,7 @@ export const block23236WithTransactions = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address:
Expand Down Expand Up @@ -219,7 +219,7 @@ export const block7134WithTxs = {
operation_identifier: {
index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address:
Expand Down Expand Up @@ -250,7 +250,7 @@ export const block7134WithTxs = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address:
Expand Down Expand Up @@ -280,7 +280,7 @@ export const block7134WithTxs = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address:
Expand Down Expand Up @@ -398,7 +398,7 @@ export const transaction987aOnGenesis = {
},
related_operations: [],
status: 'success',
type: 'transfer',
type: operationType.OUTPUT,
coin_change: {
coin_action: 'coin_created',
coin_identifier: {
Expand Down Expand Up @@ -438,7 +438,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST = {
index: 0,
network_index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -467,7 +467,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand All @@ -489,7 +489,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -519,7 +519,7 @@ export const CONSTRUCTION_PAYLOADS_MULTIPLE_INPUTS = {
index: 0,
network_index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand All @@ -544,7 +544,7 @@ export const CONSTRUCTION_PAYLOADS_MULTIPLE_INPUTS = {
index: 1,
network_index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -576,7 +576,7 @@ export const CONSTRUCTION_PAYLOADS_MULTIPLE_INPUTS = {
index: 1
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand All @@ -601,7 +601,7 @@ export const CONSTRUCTION_PAYLOADS_MULTIPLE_INPUTS = {
index: 1
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -650,7 +650,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_OUTPUTS = {
}
}
],
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -682,7 +682,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_OUTPUTS = {
}
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'ThisIsAnInvalidAddressaddr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -714,7 +714,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_OUTPUTS = {
}
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -758,7 +758,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_INPUTS = {
}
}
],
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -790,7 +790,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_INPUTS = {
}
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx',
Expand Down Expand Up @@ -823,7 +823,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_INPUTS = {
}
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand Down Expand Up @@ -865,7 +865,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_TRANSACTION_ID = {
index: 0,
network_index: 0
},
type: 'transfer',
type: operationType.INPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx',
Expand Down Expand Up @@ -895,7 +895,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_TRANSACTION_ID = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx'
Expand All @@ -918,7 +918,7 @@ export const CONSTRUCTION_PAYLOADS_REQUEST_INVALID_TRANSACTION_ID = {
index: 0
}
],
type: 'transfer',
type: operationType.OUTPUT,
status: 'success',
account: {
address: 'addr1vxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cpnkcpx',
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { Pool } from 'pg';
import { FastifyInstance } from 'fastify';
import StatusCodes from 'http-status-codes';
import { setupDatabase, setupServer, testInvalidNetworkParameters } from '../utils/test-utils';
import { CARDANO, MAINNET } from '../../../src/server/utils/constants';
import { CARDANO, MAINNET, operationType } from '../../../src/server/utils/constants';
import { generateNetworkPayload } from './common';
import packageJson from '../../../package.json';

Expand All @@ -16,7 +16,7 @@ const allow = {
successful: true
}
],
operation_types: ['transfer'],
operation_types: [operationType.INPUT, operationType.OUTPUT],
errors: [
{
code: 4001,
Expand Down
10 changes: 5 additions & 5 deletions examples/send-transaction-example.ts
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable camelcase */
/* eslint-disable new-cap */
/* eslint-disable no-console */
import delay from "delay";
import * as NaCl from "tweetnacl";
import axios from "axios";
import delay from 'delay';
import * as NaCl from 'tweetnacl';
import axios from 'axios';

const logger = console;

Expand Down Expand Up @@ -105,7 +105,7 @@ const buildOperation = (
network_index: 0,
},
related_operations: [],
type: "transfer",
type: "input",
status: "success",
account: {
address,
Expand All @@ -130,7 +130,7 @@ const buildOperation = (
network_index: 0,
},
related_operations: [],
type: "transfer",
type: "output",
status: "success",
account: {
address: destination,
Expand Down

0 comments on commit 74bc5be

Please sign in to comment.