Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
awrichar committed Sep 12, 2024
2 parents 7a81eba + 8d24e18 commit e20f84a
Show file tree
Hide file tree
Showing 32 changed files with 679 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ CREATE TABLE indexed_transactions (
"transaction_index" BIGINT NOT NULL,
"from" CHAR(40) NOT NULL,
"to" CHAR(40),
"nonce" BIGINT NOT NULL,
"contract_address" CHAR(40),
"result" TEXT,
PRIMARY KEY ("block_number", "transaction_index"),
FOREIGN KEY ("block_number") REFERENCES indexed_blocks ("number") ON DELETE CASCADE
);
CREATE INDEX indexed_transaction_id ON indexed_transactions("hash");
CREATE UNIQUE INDEX indexed_transaction_from_nonce ON indexed_transactions("from","nonce");

CREATE TABLE indexed_events (
"transaction_hash" TEXT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ CREATE TABLE indexed_transactions (
"transaction_index" BIGINT NOT NULL,
"from" CHAR(40) NOT NULL,
"to" CHAR(40),
"nonce" BIGINT NOT NULL,
"contract_address" CHAR(40),
"result" VARCHAR,
PRIMARY KEY ("block_number", "transaction_index"),
FOREIGN KEY ("block_number") REFERENCES indexed_blocks ("number") ON DELETE CASCADE
);
CREATE INDEX indexed_transaction_id ON indexed_transactions("hash");
CREATE UNIQUE INDEX indexed_transaction_from_nonce ON indexed_transactions("from","nonce");

CREATE TABLE indexed_events (
"transaction_hash" VARCHAR NOT NULL,
Expand Down
58 changes: 15 additions & 43 deletions core/go/internal/domainmgr/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ type domain struct {
config *prototk.DomainConfig
schemasBySignature map[string]statestore.Schema
schemasByID map[string]statestore.Schema
constructorABI *abi.Entry
factoryContractAddress *tktypes.EthAddress
factoryContractABI abi.ABI
privateContractABI abi.ABI

initError atomic.Pointer[error]
initDone chan struct{}
Expand Down Expand Up @@ -94,22 +91,7 @@ func (d *domain) processDomainConfig(confRes *prototk.ConfigureDomainResponse) (
}
}

err := json.Unmarshal(([]byte)(d.config.ConstructorAbiJson), &d.constructorABI)
if err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainConstructorAbiJsonInvalid)
}
if d.constructorABI.Type != abi.Constructor {
return nil, i18n.NewError(d.ctx, msgs.MsgDomainConstructorABITypeWrong, d.constructorABI.Type)
}

if err := json.Unmarshal(([]byte)(d.config.FactoryContractAbiJson), &d.factoryContractABI); err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainFactoryAbiJsonInvalid)
}

if err := json.Unmarshal(([]byte)(d.config.PrivateContractAbiJson), &d.privateContractABI); err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainPrivateAbiJsonInvalid)
}

var err error
d.factoryContractAddress, err = tktypes.ParseEthAddress(d.config.FactoryContractAddress)
if err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainFactoryAddressInvalid)
Expand Down Expand Up @@ -254,25 +236,10 @@ func (d *domain) InitDeploy(ctx context.Context, tx *components.PrivateContractD
}

// Build the init request
var abiJSON []byte
var paramsJSON []byte
constructorValues, err := d.constructorABI.Inputs.ParseJSONCtx(ctx, tx.Inputs)
if err == nil {
abiJSON, err = json.Marshal(d.constructorABI)
}
if err == nil {
// Serialize to standardized JSON before passing to domain
paramsJSON, err = tktypes.StandardABISerializer().SerializeJSONCtx(ctx, constructorValues)
}
if err != nil {
return i18n.WrapError(ctx, err, msgs.MsgDomainInvalidConstructorParams, d.constructorABI.SolString())
}

txSpec := &prototk.DeployTransactionSpecification{}
tx.TransactionSpecification = txSpec
txSpec.TransactionId = tktypes.Bytes32UUIDFirst16(tx.ID).String()
txSpec.ConstructorAbi = string(abiJSON)
txSpec.ConstructorParamsJson = string(paramsJSON)
txSpec.ConstructorParamsJson = tx.Inputs.String()

// Do the request with the domain
res, err := d.api.InitDeploy(ctx, &prototk.InitDeployRequest{
Expand Down Expand Up @@ -314,32 +281,37 @@ func (d *domain) PrepareDeploy(ctx context.Context, tx *components.PrivateContra
}
}
if res.Transaction != nil && res.Deploy == nil {
functionABI := d.factoryContractABI.Functions()[res.Transaction.FunctionName]
if functionABI == nil {
return i18n.NewError(ctx, msgs.MsgDomainFunctionNotFound, res.Transaction.FunctionName)
var functionABI abi.Entry
if err := json.Unmarshal(([]byte)(res.Transaction.FunctionAbiJson), &functionABI); err != nil {
return i18n.WrapError(d.ctx, err, msgs.MsgDomainFactoryAbiJsonInvalid)
}
inputs, err := functionABI.Inputs.ParseJSONCtx(ctx, emptyJSONIfBlank(res.Transaction.ParamsJson))
if err != nil {
return err
}
tx.DeployTransaction = nil
tx.InvokeTransaction = &components.EthTransaction{
FunctionABI: functionABI,
FunctionABI: &functionABI,
To: *d.Address(),
Inputs: inputs,
}
} else if res.Deploy != nil && res.Transaction == nil {
functionABI := d.factoryContractABI.Constructor()
if functionABI == nil {
var functionABI abi.Entry
if res.Deploy.ConstructorAbiJson == "" {
// default constructor
functionABI = &abi.Entry{Type: abi.Constructor, Inputs: abi.ParameterArray{}}
functionABI.Type = abi.Constructor
functionABI.Inputs = abi.ParameterArray{}
} else {
if err := json.Unmarshal(([]byte)(res.Deploy.ConstructorAbiJson), &functionABI); err != nil {
return i18n.WrapError(d.ctx, err, msgs.MsgDomainFactoryAbiJsonInvalid)
}
}
inputs, err := functionABI.Inputs.ParseJSONCtx(ctx, emptyJSONIfBlank(res.Deploy.ParamsJson))
if err != nil {
return err
}
tx.DeployTransaction = &components.EthDeployTransaction{
ConstructorABI: functionABI,
ConstructorABI: &functionABI,
Bytecode: res.Deploy.Bytecode,
Inputs: inputs,
}
Expand Down
Loading

0 comments on commit e20f84a

Please sign in to comment.