how do i resolve this when am deploying solidity on vs code - ethereum

project:/node_modules/#openzeppelin/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol:49:5: DeclarationError: Identifier already declared.
function finalRate() public view returns (uint256) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KATCrowdsale.sol:12:5: The previous declaration is here:
uint256 public finalRate = 10000;
^------------------------------^
,project:/node_modules/#openzeppelin/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol:42:5: DeclarationError: Identifier already declared.
function initialRate() public view returns (uint256) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KATCrowdsale.sol:11:5: The previous declaration is here:
uint256 public constant initialRate = 1000000;
^-------------------------------------------^
,project:/node_modules/#openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol:56:5: DeclarationError: Identifier already declared.
function closingTime() public view returns (uint256) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KATCrowdsale.sol:14:5: The previous declaration is here:
uint256 public closingTime = 1655053529;
^--------------------------------------^
,project:/node_modules/#openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol:49:5: DeclarationError: Identifier already declared.
function openingTime() public view returns (uint256) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KATCrowdsale.sol:13:5: The previous declaration is here:
uint256 public openingTime = 1649783129;
^-------------------------------------^
,project:/node_modules/#openzeppelin/contracts/token/ERC20/ERC20Detailed.sol:51:5: DeclarationError: Identifier already declared.
function decimals() public view returns (uint8) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KAToken.sol:11:5: The previous declaration is here:
uint256 public constant decimals = 18;
^------------------------------------^
,project:/node_modules/#openzeppelin/contracts/token/ERC20/ERC20Detailed.sol:27:5: DeclarationError: Identifier already declared.
function name() public view returns (string memory) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KAToken.sol:10:5: The previous declaration is here:
string public constant name = "Offecial Kick Ass Token";
^-----------------------------------------------------^
,project:/node_modules/#openzeppelin/contracts/token/ERC20/ERC20Detailed.sol:35:5: DeclarationError: Identifier already declared.
function symbol() public view returns (string memory) {
^ (Relevant source part starts here and spans across multiple lines).
project:/contracts/KAToken.sol:9:5: The previous declaration is here:
string public constant symbol = "OKAT";
^------------------------------------^

do remove the calls from the general contract and put them inside the constructor then fill the parameters inside the deployment codes

Related

Solidity - OpenZeppeling/utils/Counters question

When we use the Counters library, we init it usually as such
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
so far all good. Using Counters library methods for Counters.Counter (the struct in the library) and assigning _tokenIds to point to that struct. (+-? cool.)
What confuses me is the function definitions inside Counters; i.e
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
The function takes in a varaible called counter ? is it not expecting an argument ?
Where is the link between our defined _tokenIds to the smaller-case counter ?
I don't know why I find this so confusing but it seems like something's missing to me (even tho I know its not missing, just failing to understand).
Thanks in advance.
The using <library> for <type> expression allows you to use functions of the library on variables of this type. And it automatically passes the variable as the first argument of the function when you're calling it as a member function.
So in your case, Counters.current(_tokenIds) (library function) is the same as _tokenIds.current() (member function).
Docs: https://docs.soliditylang.org/en/v0.8.14/contracts.html#using-for

Check if msg.sender is a specific type of contract

As it is now, anyone can call the setMyString function in the FirstContract. I'm trying to restrict access to that function to an instance of SecondContract. But not one specific instance, any contract of type SecondContract should be able to call setMyString.
contract FirstContract{
String public myString;
function setMyString(String memory what) public {
myString=what;
}
}
contract SecondContract{
address owner;
address firstAddress;
FirstContract firstContract;
constructor(address _1st){
owner=msg.sender;
firstAddress=_1st;
firstContract=FirstContract(firstAddress);
}
function callFirst(String memory what){
require(msg.sender==owner);
firstContract.setMyString("hello");
}
}
Solidity currently doesn't have an easy way to validate an address against an interface.
You can check the bytecode, whether it contains the specified signatures (of the public properties and methods). This requires a bit larger scope than a usual StackOverflow answer, so I'm just going to describe the steps instead of writing the code.
First, define the desired list of signatures (1st 4 bytes of keccak256 hash of the name and arguments datatypes) that you're going to be looking for. You can find more info about signatures in my other answers here and here.
An example in the documentation shows how to get any address's (in your case msg.sender) bytecode as bytes (dynamic-length array).
You'll then need to loop through the returned bytes array and search for the 4-byte signatures.
If you find them all, it means that msg.sender "implements the interface". If any of the signatures is missing in the external contract, it means it doesn't implement the interface.
But... I'd really recommend you to rethink your approach to whitelisting. Yes, you'll need to maintain the list and call setIsSecondContract() when a new SecondContract wants to call the setMyString() function for the first time. But it's more gas efficient for all callers of the FirstContract's setMyString() function, as well as easier to write and test the functionality in the first place.
contract FirstContract{
String public myString;
address owner;
mapping (address => bool) isSecondContract;
modifier onlySecondContract {
require(isSecondContract[msg.sender]);
_;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function setIsSecondContract(address _address, bool _value) public onlyOwner {
isSecondContract[_address] = _value;
}
function setMyString(String memory what) public onlySecondContract {
myString=what;
}
}

No match found for function signature when NullHandling set to INTERNAL

I'm trying to implement an user defined function for Apache Drill.
The function takes float arguments (decimals do not work) and they have to be nullable in order to return zeroes.
However, when I use NullHandling.Internal and set the parameters as nullable types, the function can be no longer invoked.
SELECT tetsting_udf(1.23,4.56);
VALIDATION ERROR: (...): No match found for function signature TESTING_UDF(<DECIMAL>, <DECIMAL>)
SELECT tetsting_udf(cast(1.23 as float), cast(4.56 as float));
VALIDATION ERROR: (...): No match found for function signature TESTING_UDF(<FLOAT>, <FLOAT>)
When Float8Holders and NullHandling.NULL_IF_NULL is used, both calls above are working.
What I'm doing wrong?
#FunctionTemplate(
name = "testing_udf",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL
)
public class TestingFunction implements DrillSimpleFunc {
#Param
NullableFloat8Holder numberA;
#Param
NullableFloat8Holder numberB;
#Output
Float8Holder out;
public void setup() {
}
public void eval() {
// Whatever
}
}
For the case when FunctionTemplate.NullHandling.INTERNAL is specified, UDFs implementations with all combinations of nullability should be specified. For your case, you should specify UDFs which accepts (Float8Holder and Float8Holder), (NullableFloat8Holder and NullableFloat8Holder), (Float8Holder and NullableFloat8Holder), (NullableFloat8Holder and Float8Holder).

What does the virtual keyword, in actionscript, does?

I have found some code that uses the virtual keyword for functions, like:
package tryOut{
public class Parent {
public function Parent() {}
public function foo():void{
trace("Parent foo");
}//foo
public virtual function bar():void{
trace("Parent virtual bar");
}//bar
}//class
}//package
As far as I understand using the virtual keyword should modify the way overriding a method works, or the way using a child method would work, or something. But it seems it does nothing at all. Having the extention:
package tryOut {
public class Child extends Parent {
public function Child() {}
public override function foo():void {
trace("Child foo");
}//foo
public override function bar():void {
trace("Child virtual bar");
}//bar
}//class
}//package
The following code prints:
var parent:Parent = new Parent();
var child:Child = new Child();
parent.foo(); //Parent foo
child.foo(); //Child foo
parent.bar(); //Parent virtual bar
child.bar(); //Child virtual bar
var childCast:Parent = child as Parent;
parent.foo(); //Parent foo
childCast.foo(); //Child foo
parent.bar(); //Parent virtual bar
childCast.bar(); //Child virtual bar
So both methods work the same regarding the override. Does the virtual keyword changes something I am missing?
From the help documents (If you're using Flash, do a search for 'virtual'):
There are also several identifiers
that are sometimes referred to as
future reserved words. These
identifiers are not reserved by
ActionScript 3.0, though some of them
may be treated as keywords by software
that incorporates ActionScript 3.0.
You might be able to use many of these
identifiers in your code, but Adobe
recommends that you do not use them
because they may appear as keywords in
a subsequent version of the language.
abstract boolean byte cast
char debugger double enum
export float goto intrinsic
long prototype short synchronized
throws to transient type
virtual volatile
So in AS3, virtual does absolutely nothing.
So both methods work the same regarding the override.
What makes you think that? The tests you've shown aren't comparable.
childCast is typed as a Parent, yet you still end up calling the function in Child.
You don't check the same situation for the non-virtual method.

Proper usage of "this." keyword in C#?

I'm working through the book Head First C# (and it's going well so far), but I'm having a lot of trouble wrapping my head around the syntax involved with using the "this." keyword.
Conceptually, I get that I'm supposed to use it to avoid having a parameter mask a field of the same name, but I'm having trouble actually tracking it through their examples (also, they don't seem to have a section dedicated to that particular keyword, they just explain it and start using it in their examples).
Does anyone have any good rules of thumb they follow when applying "this."? Or any tutorials online that explain it in a different way that Head First C#?
Thanks!
Personally I only use it when I have to which is:
Constructor chaining:
public Foo(int x) : this(x, null)
{
}
public Foo(int x, string name)
{
...
}
Copying from a parameter name into a field (not as common in C# as in Java, as you'd usually use a property - but common in constructors)
public void SetName(string name)
{
// Just "name = name" would be no-op; within this method,
// "name" refers to the parameter, not the field
this.name = name;
}
Referring to this object without any members involved:
Console.WriteLine(this);
Declaring an extension method:
public static TimeSpan Days(this int days)
{
return TimeSpan.FromDays(days);
}
Some other people always use it (e.g. for other method calls) - personally I find that clutters things up a bit.
StyleCop's default coding style enforces the following rule:
A1101: The call to {method or property
name} must begin with the 'this.'
prefix to indicate that the item is a
member of the class.
Which means that every method, field, property that belongs to the current class will be prefixed by this. I was initially resistant to this rule, which makes your code more verbose, but it has grown on me since, as it makes the code pretty clear. This thread discusses the question.
I write this. if and only if it enhances readability, for example, when implementing a Comparable interface (Java, but the idea is the same):
public void compareTo(MyClass other) {
if (this.someField > other.someField) return 1;
if (this.someField < other.someField) return -1;
return 0;
}
As to parameter shadowing (e.g. in constructors): I usually give those a shorter name of the corresponding field, such as:
class Rect {
private int width, height;
public Rect(int w, int h) {
width = w;
height = h;
}
}
Basically, this gives you a reference to the current object. You can use it to access members on the object, or to pass the current object as parameters into other methods.
It is entirely unnecessary in almost all cases to place it before accessing member variables or method calls, although some style guidelines recommend it for various reasons.
Personally, I make sure I name my member variables to be clearly different from my parameters to avoid ever having to use 'this.'. For example:
private String _someData;
public String SomeData
{
get{return _someData;}
set{_someData = value;}
}
It's very much an individual preference though, and some people will recommend that you name the property and member variable the same (just case difference - 'someData' and 'SomeData') and use the this keyword when accessing the private member to indicate the difference.
So as for a rule of thumb - Avoid using it. If you find yourself using it to distinguish between local/parameters variables and member variables then rename one of them so you don't have to use 'this'.
The cases where I would use it are multiple constructors, passing a reference to other methods and in extension methods. (See Jon's answer for examples)
If you have a method inside a class which uses same class's fields, you can use this.
public class FullName
{
public string fn { set; get; }
public string sn { set; get; }
//overriding Equals method
public override bool Equals(object obj)
{
if (!(obj is FullName))
return false;
if (obj == null)
return false;
return this.fn == ((FullName)obj).fn &&
this.sn == ((FullName)obj).sn;
}
//overriding GetHashCode
public override int GetHashCode()
{
return this.fn.GetHashCode() ^ this.sn.GetHashCode();
}
}