Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes gas limit issues #43

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { environment } from '../environments/environment';
})
export class AppComponent {
title = 'GoChain Wallet';
public version: string = environment.VERSION;
public version: string = this.globals.version;
public network: string;

constructor(private globals: Globals, private walletService: WalletService, public router: Router) {
Expand Down
1 change: 1 addition & 0 deletions src/app/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { environment } from '../environments/environment';
@Injectable()
export class Globals {
network: string = 'mainnet';
version: string = '1.1.20'

constructor() {
let nw = localStorage.getItem('network');
Expand Down
7 changes: 6 additions & 1 deletion src/app/send-tx/send-tx.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<mat-hint align="start">Must start with 0x!</mat-hint>
</mat-form-field>
<mat-form-field class="full-width">
<input matInput placeholder="Gas Limit" formControlName="gasLimit">
<input matInput placeholder="Gas Limit" formControlName="deployGasLimit">
</mat-form-field>
</div>
</mat-expansion-panel>
Expand Down Expand Up @@ -92,6 +92,11 @@
<input matInput placeholder="Amount" formControlName="contractAmount">
</mat-form-field>
</div>
<div *ngIf="!functionIsConstant()">
<mat-form-field class="full-width">
<input matInput placeholder="Gas Limit" formControlName="contractGasLimit">
</mat-form-field>
</div>
</div>
</div>
<div *ngIf="functionResult != null">
Expand Down
51 changes: 30 additions & 21 deletions src/app/send-tx/send-tx.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ export class SendTxComponent implements OnInit {
to: ['', []],
amount: ['', []],
byteCode: [''],
gasLimit: ['300000', []],
deployGasLimit: ['2000000', []],
contractAddress: ['', []],
contractAmount: ['', []],
contractABI: ['', []],
contractFunction: [''],
contractGasLimit: ['500000', []],
functionParameters: this.fb.array([
])
})
Expand All @@ -71,6 +72,10 @@ export class SendTxComponent implements OnInit {
return this.func && this.func.payable
}

functionIsConstant(): boolean {
return this.func && this.func.constant;
}

addFunctionParameter() {
this.functionParameters.push(this.fb.control(''));
}
Expand Down Expand Up @@ -240,20 +245,20 @@ export class SendTxComponent implements OnInit {

this.txForm.get('byteCode').setValidators([Validators.required]);
this.txForm.get('byteCode').updateValueAndValidity();
this.txForm.get('gasLimit').setValidators([Validators.required]);
this.txForm.get('gasLimit').updateValueAndValidity();
this.txForm.get('deployGasLimit').setValidators([Validators.required]);
this.txForm.get('deployGasLimit').updateValueAndValidity();
}
if (this.step === 'contract') {
console.log("setting contract validators")
this.unvalidateSend();
this.unvalidateDeploy();

this.txForm.get('contractAddress').setValidators(null);
this.txForm.get('contractAddress').setValidators([Validators.required]);
this.txForm.get('contractAddress').updateValueAndValidity();
this.txForm.get('contractABI').setValidators(null);
this.txForm.get('contractABI').setValidators([Validators.required]);
this.txForm.get('contractABI').updateValueAndValidity();


this.txForm.get('contractGasLimit').setValidators([Validators.required]);
this.txForm.get('contractGasLimit').updateValueAndValidity();
}
}

Expand All @@ -267,15 +272,17 @@ export class SendTxComponent implements OnInit {
unvalidateDeploy(): void {
this.txForm.get('byteCode').setValidators(null);
this.txForm.get('byteCode').updateValueAndValidity();
this.txForm.get('gasLimit').setValidators(null);
this.txForm.get('gasLimit').updateValueAndValidity();
this.txForm.get('deployGasLimit').setValidators(null);
this.txForm.get('deployGasLimit').updateValueAndValidity();
}

unvalidateContract(): void {
this.txForm.get('byteCode').setValidators(null);
this.txForm.get('byteCode').updateValueAndValidity();
this.txForm.get('gasLimit').setValidators(null);
this.txForm.get('gasLimit').updateValueAndValidity();
this.txForm.get('contractAddress').setValidators(null);
this.txForm.get('contractAddress').updateValueAndValidity();
this.txForm.get('contractABI').setValidators(null);
this.txForm.get('contractABI').updateValueAndValidity();
this.txForm.get('contractGasLimit').setValidators(null);
this.txForm.get('contractGasLimit').updateValueAndValidity();
}

validate(): boolean {
Expand Down Expand Up @@ -330,23 +337,24 @@ export class SendTxComponent implements OnInit {
let pk = this.txForm.get('privateKey').value;
this.sending = true;
let tx = {};

if (this.step === 'deploy') {
// DEPLOY ===============================================
let gasLimit = this.txForm.get('deployGasLimit').value;
let byteCode = this.txForm.get('byteCode').value;
if (!byteCode.startsWith("0x")) {
byteCode = '0x' + byteCode;
}
tx = { data: byteCode, gas: '2000000' }
tx = { data: byteCode, gas: gasLimit }
} else if (this.step === 'contract') {
// USE CONTRACT ==========================================
let gasLimit = this.txForm.get('contractGasLimit').value;
let params: string[] = [];
if (this.func.inputs.length > 0) {
for (var control of this.functionParameters.controls) {
params.push(control.value);
}
}
let m = this.contract.methods[this.func.name](...params);
console.log("method:", m);
console.log("m.encode:", m.encodeABI());
let m = this.contract.methods[this.func.name](...params);
if (this.func.payable) {
console.log("Payable function")
let amount = this.txForm.get('contractAmount').value;
Expand All @@ -361,15 +369,15 @@ export class SendTxComponent implements OnInit {
Object.assign(tx, tx, {
to: this.txForm.get('contractAddress').value,
data: m.encodeABI(),
gas: '2000000'
gas: gasLimit
});
} else if (this.func.constant == false) {
console.log("Non-constant function with parameters")
Object.assign(tx, tx, {
to: this.txForm.get('contractAddress').value,
amount: 0,
data: m.encodeABI(),
gas: '2000000'
gas: gasLimit
});
} else {
console.log("Free function with parameters")
Expand All @@ -394,7 +402,8 @@ export class SendTxComponent implements OnInit {
this.sending = false;
return;
}
tx = { to: to, value: amount, gas: '2000000' }
// should probably use this since we don't ask the user here: https://web3js.readthedocs.io/en/1.0/web3-eth.html#estimategas
tx = { to: to, value: amount, gas: '100000' }
}
console.log("TX:", tx);
this.sendAndWait(pk, tx)
Expand Down
3 changes: 1 addition & 2 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
production: false,
VERSION: "1.1.20"
production: false
};