Use new transaction schema throughout monorepo
This commit is contained in:
parent
c7c4cb9bc6
commit
a394967268
@ -8,14 +8,13 @@ import {
|
||||
OrderFactory,
|
||||
orderUtils,
|
||||
provider,
|
||||
SignedTransaction,
|
||||
TransactionFactory,
|
||||
txDefaults,
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder } from '@0x/types';
|
||||
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder, SignedZeroExTransaction } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@ -41,7 +40,7 @@ describe('Exchange transactions', () => {
|
||||
|
||||
let erc20Balances: ERC20BalancesByOwner;
|
||||
let signedOrder: SignedOrder;
|
||||
let signedTx: SignedTransaction;
|
||||
let signedTx: SignedZeroExTransaction;
|
||||
let orderWithoutExchangeAddress: OrderWithoutExchangeAddress;
|
||||
let orderFactory: OrderFactory;
|
||||
let makerTransactionFactory: TransactionFactory;
|
||||
|
@ -1,14 +1,7 @@
|
||||
import { artifacts as erc20Artifacts } from '@0x/contracts-erc20';
|
||||
import { artifacts as erc721Artifacts } from '@0x/contracts-erc721';
|
||||
import {
|
||||
FillResults,
|
||||
formatters,
|
||||
LogDecoder,
|
||||
OrderInfo,
|
||||
orderUtils,
|
||||
SignedTransaction,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { SignedOrder } from '@0x/types';
|
||||
import { FillResults, formatters, LogDecoder, OrderInfo, orderUtils } from '@0x/contracts-test-utils';
|
||||
import { SignedOrder, SignedZeroExTransaction } from '@0x/types';
|
||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { MethodAbi, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
@ -206,7 +199,7 @@ export class ExchangeWrapper {
|
||||
return tx;
|
||||
}
|
||||
public async executeTransactionAsync(
|
||||
signedTx: SignedTransaction,
|
||||
signedTx: SignedZeroExTransaction,
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txHash = await this._exchange.executeTransaction.sendTransactionAsync(
|
||||
|
@ -31,7 +31,6 @@ export {
|
||||
MarketBuyOrders,
|
||||
MarketSellOrders,
|
||||
ERC721TokenIdsByOwner,
|
||||
SignedTransaction,
|
||||
OrderStatus,
|
||||
AllowanceAmountScenario,
|
||||
AssetDataScenario,
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { eip712Utils, generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { SignatureType } from '@0x/types';
|
||||
import { signTypedDataUtils } from '@0x/utils';
|
||||
import { generatePseudoRandomSalt, transactionHashUtils } from '@0x/order-utils';
|
||||
import { SignatureType, SignedZeroExTransaction } from '@0x/types';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
import { signingUtils } from './signing_utils';
|
||||
import { SignedTransaction } from './types';
|
||||
|
||||
export class TransactionFactory {
|
||||
private readonly _signerBuff: Buffer;
|
||||
@ -15,23 +13,25 @@ export class TransactionFactory {
|
||||
this._exchangeAddress = exchangeAddress;
|
||||
this._signerBuff = ethUtil.privateToAddress(this._privateKey);
|
||||
}
|
||||
public newSignedTransaction(data: string, signatureType: SignatureType = SignatureType.EthSign): SignedTransaction {
|
||||
public newSignedTransaction(
|
||||
data: string,
|
||||
signatureType: SignatureType = SignatureType.EthSign,
|
||||
): SignedZeroExTransaction {
|
||||
const salt = generatePseudoRandomSalt();
|
||||
const signerAddress = `0x${this._signerBuff.toString('hex')}`;
|
||||
const executeTransactionData = {
|
||||
const transaction = {
|
||||
salt,
|
||||
signerAddress,
|
||||
data,
|
||||
verifyingContractAddress: this._exchangeAddress,
|
||||
};
|
||||
|
||||
const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData, this._exchangeAddress);
|
||||
const eip712MessageBuffer = signTypedDataUtils.generateTypedDataHash(typedData);
|
||||
const signature = signingUtils.signMessage(eip712MessageBuffer, this._privateKey, signatureType);
|
||||
const signedTx = {
|
||||
exchangeAddress: this._exchangeAddress,
|
||||
const transactionHashBuffer = transactionHashUtils.getTransactionHashBuffer(transaction);
|
||||
const signature = signingUtils.signMessage(transactionHashBuffer, this._privateKey, signatureType);
|
||||
const signedTransaction = {
|
||||
...transaction,
|
||||
signature: `0x${signature.toString('hex')}`,
|
||||
...executeTransactionData,
|
||||
};
|
||||
return signedTx;
|
||||
return signedTransaction;
|
||||
}
|
||||
}
|
||||
|
@ -107,14 +107,6 @@ export enum ContractName {
|
||||
BalanceThresholdFilter = 'BalanceThresholdFilter',
|
||||
}
|
||||
|
||||
export interface SignedTransaction {
|
||||
exchangeAddress: string;
|
||||
salt: BigNumber;
|
||||
signerAddress: string;
|
||||
data: string;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
export interface TransferAmountsByMatchOrders {
|
||||
// Left Maker
|
||||
amountBoughtByLeftMaker: BigNumber;
|
||||
|
@ -28,11 +28,12 @@ export class TransactionEncoder {
|
||||
public getTransactionHex(data: string, salt: BigNumber, signerAddress: string): string {
|
||||
const exchangeAddress = this._getExchangeContract().address;
|
||||
const executeTransactionData = {
|
||||
verifyingContractAddress: exchangeAddress,
|
||||
salt,
|
||||
signerAddress,
|
||||
data,
|
||||
};
|
||||
const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData, exchangeAddress);
|
||||
const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData);
|
||||
const eip712MessageBuffer = signTypedDataUtils.generateTypedDataHash(typedData);
|
||||
const messageHex = `0x${eip712MessageBuffer.toString('hex')}`;
|
||||
return messageHex;
|
||||
|
@ -12,7 +12,7 @@ import { chaiSetup } from './utils/chai_setup';
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe.only('0x transaction hashing', () => {
|
||||
describe('0x transaction hashing', () => {
|
||||
describe('#getTransactionHashHex', () => {
|
||||
const expectedTransactionHash = '0x82c9bb2dcac4f868ec7a15c20ff6175cfc384c20ae6a872aa0342a840f108c2b';
|
||||
const fakeVerifyingContractAddress = '0x5e72914535f202659083db3a02c984188fa26e9f';
|
||||
|
Loading…
x
Reference in New Issue
Block a user